package com.taobao.api;

import static com.taobao.api.ApiConstants.BANNER;
import static com.taobao.api.ApiConstants.CID;
import static com.taobao.api.ApiConstants.FIELDS;
import static com.taobao.api.ApiConstants.HAS_DISCOUNT;
import static com.taobao.api.ApiConstants.HAS_SHOWCASE;
import static com.taobao.api.ApiConstants.ORDER_BY;
import static com.taobao.api.ApiConstants.PAGE_NO;
import static com.taobao.api.ApiConstants.PAGE_SIZE;
import static com.taobao.api.ApiConstants.Q;
import static com.taobao.api.ApiConstants.SELLER_CIDS;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.taobao.api.convert.TaobaoBrandJSONConvert;
import com.taobao.api.convert.TaobaoItemExtraJSONConvert;
import com.taobao.api.convert.TaobaoItemJSONConvert;
import com.taobao.api.convert.TaobaoPostageJSONConvert;
import com.taobao.api.convert.TaobaoProductJSONConvert;
import com.taobao.api.convert.TaobaoRefundJSONConvert;
import com.taobao.api.convert.TaobaoRefundMessageJSONConvert;
import com.taobao.api.convert.TaobaoSellerJSONConvert;
import com.taobao.api.convert.TaobaoShippingJSONConvert;
import com.taobao.api.convert.TaobaoShopJSONConvert;
import com.taobao.api.convert.TaobaoSkuJSONConvert;
import com.taobao.api.convert.TaobaoSpuJSONConvert;
import com.taobao.api.convert.TaobaoSuiteJSONConvert;
import com.taobao.api.convert.TaobaoTradeJSONConvert;
import com.taobao.api.convert.TaobaoUserJSONConvert;
import com.taobao.api.convert.TaobaoVasJSONConvert;
import com.taobao.api.json.JSONArray;
import com.taobao.api.json.JSONException;
import com.taobao.api.json.JSONObject;
import com.taobao.api.model.*;
import com.taobao.api.util.DateUtil;

/**
 * 淘宝对外部提供的REST API客户端
 * 
 * 注意，默认是SIP入口。使用淘宝API入口需要设置：
 * 
 * @version 2008-8-28
 * @author <a href="mailto:zixue@taobao.com">zixue</a>
 */
public class TaobaoJsonRestClient extends AbstractTaobaoRestClient implements
		TaobaoRestClient {

	public TaobaoJsonRestClient(String appkey, String secret)
			throws TaobaoApiException {
		this(appkey, secret, false);
	}

	public TaobaoJsonRestClient(String appkey, String secret, boolean isSandbox)
			throws TaobaoApiException {
		this(isSandbox ? ApiConstants.API_SANDBOX_SERVICE_URL
				: ApiConstants.API_SERVICE_URL, appkey, secret);
	}

	public TaobaoJsonRestClient(String serviceUrl, String appkey, String secret)
			throws TaobaoApiException {
		this(serviceUrl, ApiConstants.DEFAULT_SERVICE_VERSION, appkey, secret);
	}

	public TaobaoJsonRestClient(String serviceUrl, String version,
			String appkey, String secret) throws TaobaoApiException {
		super(serviceUrl, version, appkey, secret);
	}

	protected String getApiKeyName() {
		return ApiConstants.APIKEY;
	}

	protected String getMethodName() {
		return ApiConstants.METHOD;
	}

	protected String getSignName() {
		return ApiConstants.SIGN;
	}

	protected String getSessionIdName() {
		return ApiConstants.SESSION;
	}

	protected String getTimestampName() {
		return ApiConstants.TIMESTAMP;
	}

	/**
	 * 通过系统平台（sip）的检查（签名、绑定用户）后，检测淘宝的接口是否调用正常
	 * 
	 * @param response
	 * @param json
	 * @throws JSONException
	 */
	protected void parseError(TaobaoResponse response, JSONObject json)
			throws JSONException {
		if (json.has(ApiConstants.ERROR_RSP)) {
			JSONObject errorRsp = json.getJSONObject(ApiConstants.ERROR_RSP);
			response.setErrorCode(errorRsp.getString(ApiConstants.ERROR_CODE));
			response.setMsg(errorRsp.getString(ApiConstants.ERROR_MSG));
		}
	}

	/**
	 * 设置返回的response中totalResults(取得到商品、交易等的 总数)对应字段的值
	 * 
	 * @param rsp
	 *            JSONObject
	 * @param listUrlResponse
	 *            返回的response对象
	 * @throws NumberFormatException
	 * @throws JSONException
	 */
	protected void setTotalResults(JSONObject rsp,
			TaobaoListResponse listUrlResponse) throws NumberFormatException,
			TaobaoApiException {
		if (rsp.has(ApiConstants.TOTALRESULTS)) {
			try {
				listUrlResponse.setTotalResults(Integer.parseInt(rsp
						.getString(ApiConstants.TOTALRESULTS)));
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
	}

	protected JSONObject getRsp(JSONObject json) throws JSONException {
		return json.getJSONObject(ApiConstants.RSP);
	}

	/*
	 * --------------------------------------------------------------------------
	 * ----------------------------------------------------------------
	 */

	// 商品部分
	public ItemAddResponse itemAdd(ItemAddRequest itemAddRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareItemAdd(itemAddRequest);
		return sendItemAdd(params, itemAddRequest, sessionId);
	}

	protected Map<String, Object> prepareItemAdd(ItemAddRequest itemAddRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.VALID_THRU, itemAddRequest.getValidThru());
		params.put(ApiConstants.HAS_INVOICE, itemAddRequest.getHasInvoice());
		params.put(ApiConstants.HAS_WARRANTY, itemAddRequest.getHasWarranty());
		params.put(ApiConstants.SELLER_CIDS, itemAddRequest.getSellerCids());
		params.put(ApiConstants.HAS_DISCOUNT, itemAddRequest.getHasDiscount());
		params.put(ApiConstants.POST_FEE, itemAddRequest.getPostFee());
		params.put(ApiConstants.EXPRESS_FEE, itemAddRequest.getExpressFee());
		params.put(ApiConstants.LIST_TIME, itemAddRequest.getListTime());
		params.put(ApiConstants.INCREMENT, itemAddRequest.getIncrement());
		params.put(ApiConstants.AUTO_REPOST, itemAddRequest.getAutoRepost());
		params.put(ApiConstants.HAS_SHOWCASE, itemAddRequest.getHasShowcase());
		params.put(ApiConstants.EMS_FEE, itemAddRequest.getEmsFee());
		params.put(ApiConstants.CID, itemAddRequest.getCid());
		params.put(ApiConstants.PROPS, itemAddRequest.getProps());
		params.put(ApiConstants.NUM, itemAddRequest.getNum());
		params.put(ApiConstants.PRICE, itemAddRequest.getPrice());
		params.put(ApiConstants.TITLE, itemAddRequest.getTitle());
		params.put(ApiConstants.DESC, itemAddRequest.getDesc());
		params.put(ApiConstants.TYPE, itemAddRequest.getType());
		params.put(ApiConstants.STUFF_STATUS, itemAddRequest.getStuffStatus());
		params.put(ApiConstants.APPROVE_STATUS, itemAddRequest
				.getApproveStatus());
		params
				.put(ApiConstants.FREIGHT_PAYER, itemAddRequest
						.getFreightPayer());
		params.put(ApiConstants.OUTER_ID, itemAddRequest.getOuterId());
		if (itemAddRequest.getLocation() != null) {
			params.put(ApiConstants.LOCATION_STATE, (itemAddRequest
					.getLocation().getState()));
			params.put(ApiConstants.LOCATION_CITY, (itemAddRequest
					.getLocation().getCity()));
		}
		params
				.put(ApiConstants.AUCTION_POINT, itemAddRequest
						.getAuctionPoint());
		params.put(ApiConstants.PROPERTY_ALIAS, itemAddRequest
				.getPropertyAlias());
		params.put(ApiConstants.SKU_PROPERTIES, itemAddRequest
				.getSkuProperties());
		params.put(ApiConstants.SKU_QUANTITIES, itemAddRequest
				.getSkuQuantities());
		params.put(ApiConstants.SKU_PRICES, itemAddRequest.getSkuPrices());
		params.put(ApiConstants.SKU_OUTER_IDS, itemAddRequest.getSkuOuterIds());
		params.put(ApiConstants.POSTAGE_ID, itemAddRequest.getPostageId());
		params.put(ApiConstants.INPUT_PIDS, itemAddRequest.getInputPids());
		params.put(ApiConstants.INPUT_STR, itemAddRequest.getInputStr());
		params.put(ApiConstants.LANG, itemAddRequest.getLang());
		params.put(ApiConstants.IS_TAOBAO, itemAddRequest.getIsTaobao());
		params.put(ApiConstants.IS_EX, itemAddRequest.getIsEx());
		params.put(ApiConstants.PRODUCT_ID, itemAddRequest.getProductId());
		return params;
	}

	protected ItemAddResponse sendItemAdd(Map<String, Object> params,
			ItemAddRequest itemAddRequest, String sessionId)
			throws TaobaoApiException {
		ItemAddResponse itemAddResponse = getItemAddResponse(itemAddRequest,
				sessionId, params);
		// 平台成功访问
		if (itemAddResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(itemAddResponse.getBody());
				parseError(itemAddResponse, json);
				// 访问淘宝成功
				if (itemAddResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						JSONObject item = items.getJSONObject(0);
						Item addedItem = new Item();
						try {
							addedItem.setCreated(DateUtil.strToDate(item
									.getString(ApiConstants.CREATED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						addedItem.setIid(item.getString(ApiConstants.IID));
						itemAddResponse.setItem(addedItem);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemAddResponse;
	}

	/**
	 * 获得调用添加商品API的响应response
	 * 
	 * @param itemAddRequest
	 *            添加商品的请求
	 * @param sessionId
	 *            请求所包含的session id
	 * @param paramsMap
	 *            请求参数
	 * @return ItemAddResponse
	 * @throws TaobaoApiException
	 */
	private ItemAddResponse getItemAddResponse(ItemAddRequest itemAddRequest,
			String sessionId, Map<String, Object> paramsMap)
			throws TaobaoApiException {
		TaobaoResponse rsp = null;
		// 根据添加商品是否有图片选择不同的请求方法
		if (itemAddRequest.getImage() != null) {
			rsp = this.getFetch().fetchWithFile(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.ITEM_ADD.getMethod(),
							sessionId, paramsMap), itemAddRequest.getImage());
		} else {
			rsp = this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.ITEM_ADD.getMethod(),
							sessionId, paramsMap));
		}
		return new ItemAddResponse(rsp);
	}

	public ItemExtraGetResponse itemExtraGet(ItemExtraGetRequest request,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, request.getFields());
		params.put(ApiConstants.TYPE, request.getType());
		params.put(ApiConstants.IID, request.getIid());
		params.put(ApiConstants.NICK, request.getNick());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMEXTRA_GET.getMethod(),
						sessionId, params));
		ItemExtraGetResponse itemExtraResponse = new ItemExtraGetResponse(
				response);
		// 平台成功访问
		if (itemExtraResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemExtraResponse.getBody());
				parseError(itemExtraResponse, json);
				// 访问淘宝成功
				if (itemExtraResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMEXTRAS)) {
						JSONArray itemextras = rsp
								.getJSONArray(ApiConstants.ITEMEXTRAS);
						JSONObject itemextra = itemextras.getJSONObject(0);
						itemExtraResponse
								.setItemextra(TaobaoItemExtraJSONConvert
										.convertJsonToItemExtra(itemextra));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemExtraResponse;
	}

	public ItemExtraAddResponse itemExtraAdd(ItemExtraAddRequest request,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.TITLE, request.getTitle());
		params.put(ApiConstants.TYPE, request.getType());
		params.put(ApiConstants.IID, request.getIid());
		params.put(ApiConstants.DESC, request.getDesc());
		params.put(ApiConstants.MEMO, request.getMemo());
		params.put(ApiConstants.FEATURE, request.getFeature());
		params.put(ApiConstants.SKU_PRICES, request.getSkuPrices());
		params.put(ApiConstants.SKU_PROPERTIES, request.getSkuProperties());
		params.put(ApiConstants.SKU_QUANTITIES, request.getSkuQuantities());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMEXTRA_ADD.getMethod(),
						sessionId, params));
		ItemExtraAddResponse itemExtraAddResponse = new ItemExtraAddResponse(
				response);
		// 平台成功访问
		if (itemExtraAddResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemExtraAddResponse.getBody());
				parseError(itemExtraAddResponse, json);
				// 访问淘宝成功
				if (itemExtraAddResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMEXTRAS)) {
						JSONArray itemextras = rsp
								.getJSONArray(ApiConstants.ITEMEXTRAS);
						JSONObject itemextra = itemextras.getJSONObject(0);
						ItemExtra updatedItem = new ItemExtra();
						try {
							updatedItem.setModified(DateUtil
									.strToDate(itemextra
											.getString(ApiConstants.CREATED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						updatedItem.setIid(itemextra
								.getString(ApiConstants.EID));
						itemExtraAddResponse.setItemextra(updatedItem);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemExtraAddResponse;
	}

	public ItemExtraUpdateResponse itemExtraUpdate(
			ItemExtraUpdateRequest request, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.TITLE, request.getTitle());
		params.put(ApiConstants.TYPE, request.getType());
		params.put(ApiConstants.IID, request.getIid());
		params.put(ApiConstants.DESC, request.getDesc());
		params.put(ApiConstants.MEMO, request.getMemo());
		params.put(ApiConstants.FEATURE, request.getFeature());
		params.put(ApiConstants.SKU_PRICES, request.getSkuPrices());
		params.put(ApiConstants.SKU_PROPERTIES, request.getSkuProperties());
		params.put(ApiConstants.SKU_QUANTITIES, request.getSkuQuantities());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMEXTRA_ADD.getMethod(),
						sessionId, params));
		ItemExtraUpdateResponse itemExtraUpdateResponse = new ItemExtraUpdateResponse(
				response);
		// 平台成功访问
		if (itemExtraUpdateResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemExtraUpdateResponse.getBody());
				parseError(itemExtraUpdateResponse, json);
				// 访问淘宝成功
				if (itemExtraUpdateResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMEXTRAS)) {
						JSONArray itemextras = rsp
								.getJSONArray(ApiConstants.ITEMEXTRAS);
						JSONObject itemextra = itemextras.getJSONObject(0);
						ItemExtra updatedItem = new ItemExtra();
						try {
							updatedItem.setModified(DateUtil
									.strToDate(itemextra
											.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						updatedItem.setIid(itemextra
								.getString(ApiConstants.EID));
						itemExtraUpdateResponse.setItemextra(updatedItem);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemExtraUpdateResponse;
	}

	/**
	 * 获取单个商品
	 * 
	 * @param itemGetRequest
	 * @return ItemGetResponse
	 * @throws TaobaoApiException
	 */
	public ItemGetResponse itemGet(ItemGetRequest itemGetRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareItemGet(itemGetRequest);
		return sendItemGet(params, sessionId);
	}

	protected Map<String, Object> prepareItemGet(ItemGetRequest itemGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, itemGetRequest.getFields());
		params.put(ApiConstants.NICK, itemGetRequest.getNick());
		params.put(ApiConstants.IID, itemGetRequest.getIid());
		params.put(ApiConstants.NUM_IID, itemGetRequest.getNumIid());
		return params;
	}

	protected ItemGetResponse sendItemGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_GET.getMethod(),
						sessionId, params));
		ItemGetResponse itemGetResponse = new ItemGetResponse(response);
		// 平台成功访问
		if (itemGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemGetResponse.getBody());
				parseError(itemGetResponse, json);
				// 访问淘宝成功
				if (itemGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						JSONObject item = items.getJSONObject(0);
						itemGetResponse.setItem(TaobaoItemJSONConvert
								.convertJsonToItem(item));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemGetResponse;
	}

	public ItemGetResponse itemGet(ItemGetRequest itemGetRequest)
			throws TaobaoApiException {
		return this.itemGet(itemGetRequest, null);
	}

	/**
	 * 更新单个商品信息
	 * 
	 * @param itemUpdateRequest
	 * @return ItemUpdateResponse
	 * @throws TaobaoApiException
	 */
	public ItemUpdateResponse itemUpdate(ItemUpdateRequest itemUpdateRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareItemUpdate(itemUpdateRequest);
		return sendItemUpdate(itemUpdateRequest, params, sessionId);
	}

	protected Map<String, Object> prepareItemUpdate(
			ItemUpdateRequest itemUpdateRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将itemUpdateRequest请求中的参数添加到params
		params.put(ApiConstants.IID, itemUpdateRequest.getIid());
		params.put(ApiConstants.CID, itemUpdateRequest.getCid());
		params.put(ApiConstants.PROPS, itemUpdateRequest.getProps());
		params.put(ApiConstants.NUM, itemUpdateRequest.getNum());
		params.put(ApiConstants.PRICE, itemUpdateRequest.getPrice());
		params.put(ApiConstants.STUFF_STATUS, itemUpdateRequest
				.getStuffStatus());
		params.put(ApiConstants.TITLE, itemUpdateRequest.getTitle());
		params.put(ApiConstants.DESC, itemUpdateRequest.getDesc());
		params.put(ApiConstants.VALID_THRU, itemUpdateRequest.getValidThru());
		params.put(ApiConstants.HAS_INVOICE, itemUpdateRequest.getHasInvoice());
		params.put(ApiConstants.HAS_WARRANTY, itemUpdateRequest
				.getHasWarranty());
		params.put(ApiConstants.SELLER_CIDS, itemUpdateRequest.getSellerCids());
		params.put(ApiConstants.HAS_DISCOUNT, itemUpdateRequest
				.getHasDiscount());
		params.put(ApiConstants.POST_FEE, itemUpdateRequest.getPostFee());
		params.put(ApiConstants.EXPRESS_FEE, itemUpdateRequest.getExpressFee());
		params.put(ApiConstants.LIST_TIME, itemUpdateRequest.getListTime());
		params.put(ApiConstants.INCREMENT, itemUpdateRequest.getIncrement());
		params.put(ApiConstants.AUTO_REPOST, itemUpdateRequest.getAutoRepost());
		params.put(ApiConstants.HAS_SHOWCASE, itemUpdateRequest
				.getHasShowcase());
		params.put(ApiConstants.EMS_FEE, itemUpdateRequest.getEmsFee());
		params.put(ApiConstants.APPROVE_STATUS, itemUpdateRequest
				.getApproveStatus());
		params.put(ApiConstants.FREIGHT_PAYER, itemUpdateRequest
				.getFreightPayer());
		if (itemUpdateRequest.getLocation() != null) {
			params.put(ApiConstants.LOCATION_STATE, (itemUpdateRequest
					.getLocation().getState()));
			params.put(ApiConstants.LOCATION_CITY, (itemUpdateRequest
					.getLocation().getCity()));
		}
		params.put(ApiConstants.AUCTION_POINT, itemUpdateRequest
				.getAuctionPoint());
		params.put(ApiConstants.PROPERTY_ALIAS, itemUpdateRequest
				.getPropertyAlias());
		params.put(ApiConstants.SKU_IDS, itemUpdateRequest.getSkuIds());
		params.put(ApiConstants.SKU_PROPERTIES, itemUpdateRequest
				.getSkuProperties());
		params.put(ApiConstants.SKU_QUANTITIES, itemUpdateRequest
				.getSkuQuantities());
		params.put(ApiConstants.SKU_PRICES, itemUpdateRequest.getSkuPrices());
		params.put(ApiConstants.SKU_OUTER_IDS, itemUpdateRequest
				.getSkuOuterIds());
		params.put(ApiConstants.POSTAGE_ID, itemUpdateRequest.getPostageId());
		params.put(ApiConstants.INPUT_PIDS, itemUpdateRequest.getInputPids());
		params.put(ApiConstants.INPUT_STR, itemUpdateRequest.getInputStr());
		params.put(ApiConstants.LANG, itemUpdateRequest.getLang());
		params.put(ApiConstants.OUTER_ID, itemUpdateRequest.getOuterId());
		params.put(ApiConstants.IS_TAOBAO, itemUpdateRequest.getIsTaobao());
		params.put(ApiConstants.IS_EX, itemUpdateRequest.getIsEx());
		params.put(ApiConstants.PRODUCT_ID, itemUpdateRequest.getProductId());
		return params;
	}

	protected ItemUpdateResponse sendItemUpdate(
			ItemUpdateRequest itemUpdateRequest, Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		// 请求调用更新商品API，返回 响应的response
		ItemUpdateResponse itemUpdateResponse = getUpdateResponse(
				itemUpdateRequest, sessionId, params);
		// 平台成功访问
		if (itemUpdateResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(itemUpdateResponse.getBody());
				parseError(itemUpdateResponse, json);
				// 访问淘宝成功
				if (itemUpdateResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						JSONObject item = items.getJSONObject(0);
						Item updatedItem = new Item();
						try {
							updatedItem.setModified(DateUtil.strToDate(item
									.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						updatedItem.setIid(item.getString(ApiConstants.IID));
						itemUpdateResponse.setItem(updatedItem);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemUpdateResponse;
	}

	/**
	 * 获得更新商品API的相应response
	 * 
	 * @param req
	 *            更新商品的请求
	 * @param sessionId
	 *            请求中包含的session id
	 * @param params
	 *            请求参数
	 * @return
	 * @throws TaobaoApiException
	 */
	private ItemUpdateResponse getUpdateResponse(ItemUpdateRequest req,
			String sessionId, Map<String, Object> params)
			throws TaobaoApiException {
		TaobaoResponse rsp = null;
		// 根据添加商品是否有图片选择不同的请求方法
		if (req.getImage() != null) {
			rsp = this.getFetch().fetchWithFile(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.ITEM_UPDATE.getMethod(),
							sessionId, params), req.getImage());
		} else {
			rsp = this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.ITEM_UPDATE.getMethod(),
							sessionId, params));
		}
		return new ItemUpdateResponse(rsp);
	}

	/**
	 * 批量获取商品信息
	 * 
	 * @param itemUpdateRequest
	 * @return ItemUpdateResponse
	 * @throws TaobaoApiException
	 */
	public ItemsGetResponse itemsGet(ItemsGetRequest itemsGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// // 先将itemsGetRequest请求中的参数添加到params
		params.put(ApiConstants.Q, itemsGetRequest.getQ());
		params.put(ApiConstants.FIELDS, itemsGetRequest.getFields());
		params.put(ApiConstants.START_PRICE, itemsGetRequest.getStartPrice());
		params.put(ApiConstants.END_PRICE, itemsGetRequest.getEndPrice());
		params.put(ApiConstants.CID, itemsGetRequest.getCid());
		params.put(ApiConstants.PAGE_NO, itemsGetRequest.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, itemsGetRequest.getPageSize());
		params.put(ApiConstants.ORDER_BY, itemsGetRequest.getOrderBy());
		params.put(ApiConstants.NICKS, itemsGetRequest.getNicks());
		params.put(ApiConstants.PROPS, itemsGetRequest.getProps());
		params.put(ApiConstants.PRODUCT_ID, itemsGetRequest.getProductId());
		params.put(ApiConstants.WW_STATUS, itemsGetRequest.getWwStatus());
		params.put(ApiConstants.POST_FREE, itemsGetRequest.getPostFree());
		params.put(ApiConstants.LOCATION_CITY, itemsGetRequest.getCity());
		params.put(ApiConstants.LOCATION_STATE, itemsGetRequest.getState());
		params.put(ApiConstants.ITEM_TYPE, itemsGetRequest.getItemType());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMS_GET.getMethod(),
						params));
		ItemsGetResponse itemsGetResponse = new ItemsGetResponse(response);
		// 平台访问成功
		if (itemsGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemsGetResponse.getBody());
				parseError(itemsGetResponse, json);
				// 访问淘宝成功
				if (itemsGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						itemsGetResponse.setItems(TaobaoItemJSONConvert
								.convertJsonArrayToItemList(items));
					}
					setTotalResults(rsp, itemsGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemsGetResponse;
	}

	/**
	 * 批量获取商品信息
	 * 
	 * @param itemUpdateRequest
	 * @return ItemUpdateResponse
	 * @throws TaobaoApiException
	 */
	public ItemsSearchResponse itemsSearch(ItemsSearchRequest itemsSearchRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// // 先将itemsGetRequest请求中的参数添加到params
		params.put(ApiConstants.Q, itemsSearchRequest.getQ());
		params.put(ApiConstants.FIELDS, itemsSearchRequest.getFields());
		params
				.put(ApiConstants.START_PRICE, itemsSearchRequest
						.getStartPrice());
		params.put(ApiConstants.END_PRICE, itemsSearchRequest.getEndPrice());
		params.put(ApiConstants.CID, itemsSearchRequest.getCid());
		params.put(ApiConstants.PAGE_NO, itemsSearchRequest.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, itemsSearchRequest.getPageSize());
		params.put(ApiConstants.ORDER_BY, itemsSearchRequest.getOrderBy());
		params.put(ApiConstants.NICKS, itemsSearchRequest.getNicks());
		params.put(ApiConstants.PROPS, itemsSearchRequest.getProps());
		params.put(ApiConstants.PRODUCT_ID, itemsSearchRequest.getProductId());
		params.put(ApiConstants.WW_STATUS, itemsSearchRequest.getWwStatus());
		params.put(ApiConstants.POST_FREE, itemsSearchRequest.getPostFree());
		params.put(ApiConstants.LOCATION_CITY, itemsSearchRequest.getCity());
		params.put(ApiConstants.LOCATION_STATE, itemsSearchRequest.getState());
		params.put(ApiConstants.ITEM_TYPE, itemsSearchRequest.getItemType());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMS_SEARCH.getMethod(),
						params));
		ItemsSearchResponse itemsSearchResponse = new ItemsSearchResponse(
				response);
		// 平台访问成功
		if (itemsSearchResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemsSearchResponse.getBody());
				parseError(itemsSearchResponse, json);
				// 访问淘宝成功
				if (itemsSearchResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEM_SEARCHS)) {
						JSONArray items = rsp
								.getJSONArray(ApiConstants.ITEM_SEARCHS);
						JSONObject item = items.getJSONObject(0);
						itemsSearchResponse.setSearch(TaobaoItemJSONConvert
								.convertJsonToItemSearch(item));
					}
					setTotalResults(rsp, itemsSearchResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemsSearchResponse;
	}

	/**
	 * 得到当前会话用户（做为卖家）的出售中商品列表
	 * 
	 * @param itemsOnSaleGetRequest
	 * @return ItemsGetResponse
	 * @throws TaobaoApiException
	 */
	public ItemsGetResponse itemsOnSaleGet(
			ItemsOnSaleGetRequest itemsOnSaleGetRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareItemsOnSaleGet(itemsOnSaleGetRequest);
		return sendItemsOnSaleGet(params, sessionId);
	}
	public ItemsGetResponse itemsAllGet(
			ItemsAllGetRequest itemsAllGetRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareItemsAllGet(itemsAllGetRequest);
		return sendItemsAllGet(params, sessionId);
	}
	/**
	 * 数据准备，将itemsOnSaleRequest数据封装为Map对象返回
	 * 
	 * @param ItemStatsGetRequest
	 * @return Map<String, Object>
	 * @throws
	 */
	protected Map<String, Object> prepareItemsOnSaleGet(
			ItemsOnSaleGetRequest itemsOnSaleGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(FIELDS, itemsOnSaleGetRequest.getFields());
		params.put(HAS_DISCOUNT, itemsOnSaleGetRequest.getHasDiscount());
		params.put(HAS_SHOWCASE, itemsOnSaleGetRequest.getHasShowcase());
		params.put(Q, itemsOnSaleGetRequest.getQ());
		params.put(CID, itemsOnSaleGetRequest.getCid());
		params.put(SELLER_CIDS, itemsOnSaleGetRequest.getSellerCids());
		params.put(PAGE_NO, itemsOnSaleGetRequest.getPageNo());
		params.put(PAGE_SIZE, itemsOnSaleGetRequest.getPageSize());
		params.put(ORDER_BY, itemsOnSaleGetRequest.getOrderBy());
		params.put(ApiConstants.IS_TAOBAO, itemsOnSaleGetRequest.getIsTaobao());
		params.put(ApiConstants.IS_EX, itemsOnSaleGetRequest.getIsEx());
		return params;
	}
	protected Map<String, Object> prepareItemsAllGet(
			ItemsAllGetRequest itemsAllGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(FIELDS, itemsAllGetRequest.getFields());
		params.put(Q, itemsAllGetRequest.getQ());
		params.put(CID, itemsAllGetRequest.getCid());
		params.put(SELLER_CIDS, itemsAllGetRequest.getSellerCids());
		params.put(PAGE_NO, itemsAllGetRequest.getPageNo());
		params.put(PAGE_SIZE, itemsAllGetRequest.getPageSize());
		params.put(ORDER_BY, itemsAllGetRequest.getOrderBy());
		return params;
	}
	protected ItemsGetResponse sendItemsOnSaleGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(
						TaobaoApiMethod.ITEMS_ONSALE_GET.getMethod(),
						sessionId, params));
		ItemsGetResponse itemsOnSaleGetResponse = new ItemsGetResponse(response);
		// 平台访问成功
		if (itemsOnSaleGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemsOnSaleGetResponse.getBody());
				parseError(itemsOnSaleGetResponse, json);
				// 访问淘宝成功
				if (itemsOnSaleGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						itemsOnSaleGetResponse.setItems(TaobaoItemJSONConvert
								.convertJsonArrayToItemList(items));
					}
					setTotalResults(rsp, itemsOnSaleGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemsOnSaleGetResponse;
	}
	protected ItemsGetResponse sendItemsAllGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(
						TaobaoApiMethod.ITEMS_ALL_GET.getMethod(),
						sessionId, params));
		ItemsGetResponse itemsAllGetResponse = new ItemsGetResponse(response);
		// 平台访问成功
		if (itemsAllGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemsAllGetResponse.getBody());
				parseError(itemsAllGetResponse, json);
				// 访问淘宝成功
				if (itemsAllGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						itemsAllGetResponse.setItems(TaobaoItemJSONConvert
								.convertJsonArrayToItemList(items));
					}
					setTotalResults(rsp, itemsAllGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemsAllGetResponse;
	}
	/**
	 * 数据准备，将itemsInStockRequest数据封装为Map对象返回
	 * 
	 * @param ItemStatsGetRequest
	 * @return Map<String, Object>
	 * @throws
	 */
	protected Map<String, Object> prepareItemsInStockGet(
			ItemsInventoryGetRequest itemsInStockGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(FIELDS, itemsInStockGetRequest.getFields());
		params.put(BANNER, itemsInStockGetRequest.getBanner());
		params.put(Q, itemsInStockGetRequest.getQ());
		params.put(PAGE_NO, itemsInStockGetRequest.getPageNo());
		params.put(PAGE_SIZE, itemsInStockGetRequest.getPageSize());
		params.put(ORDER_BY, itemsInStockGetRequest.getOrderBy());
		params.put(ApiConstants.IS_TAOBAO, itemsInStockGetRequest.getIsTaobao());
		params.put(ApiConstants.IS_EX, itemsInStockGetRequest.getIsEx());
		return params;
	}

	protected ItemsGetResponse getItemsInventory(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMS_INVENTORY_GET
						.getMethod(), sessionId, params));
		ItemsGetResponse itemsInStockGetResponse = new ItemsGetResponse(
				response);
		// 平台访问成功
		if (itemsInStockGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemsInStockGetResponse.getBody());
				parseError(itemsInStockGetResponse, json);
				// 淘宝访问成功
				if (itemsInStockGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						itemsInStockGetResponse.setItems(TaobaoItemJSONConvert
								.convertJsonArrayToItemList(items));
					}
					setTotalResults(rsp, itemsInStockGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemsInStockGetResponse;
	}

	public ItemsGetResponse itemsInStockGet(ItemsInStockGetRequest req, String sessionId)
			throws TaobaoApiException {
		return this.itemsInventoryGet(req, sessionId);
	}

	public ItemsGetResponse itemsInventoryGet(ItemsInventoryGetRequest req, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareItemsInStockGet(req);
		return getItemsInventory(params, sessionId);
	}

	/**
	 * 此接口用于商品下架
	 * 
	 * @param itemUpdateDelistingRequest
	 * @return ItemUpdateDelistingResponse
	 * @throws TaobaoApiException
	 */
	public ItemUpdateDelistingResponse itemUpdateDelisting(
			ItemUpdateDelistingRequest itemUpdateDelistingRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareItemDelisting(itemUpdateDelistingRequest);
		return sendItemUpdateDelisting(params, sessionId);
	}

	protected Map<String, Object> prepareItemDelisting(
			ItemUpdateDelistingRequest itemUpdateDelistingRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将itemUpdateDelisting请求中的参数添加到params
		params.put(ApiConstants.IID, itemUpdateDelistingRequest.getIid());
		return params;
	}

	protected ItemUpdateDelistingResponse sendItemUpdateDelisting(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_UPDATE_DELISTING
						.getMethod(), sessionId, params));
		ItemUpdateDelistingResponse itemUpdateDelistingResponse = new ItemUpdateDelistingResponse(
				response);
		// 平台成功访问
		if (itemUpdateDelistingResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(itemUpdateDelistingResponse
						.getBody());
				parseError(itemUpdateDelistingResponse, json);
				// 访问淘宝成功
				if (itemUpdateDelistingResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						JSONObject item = items.getJSONObject(0);
						itemUpdateDelistingResponse.setIid(item
								.getString(ApiConstants.IID));
						try {
							itemUpdateDelistingResponse.setModified(DateUtil
									.strToDate(item
											.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemUpdateDelistingResponse;
	}

	/**
	 * 此接口方法用以一口价商品的上架
	 * 
	 * @param itemUpdateListingRequest
	 * @return ItemUpdateListingResponse
	 * @throws TaobaoApiException
	 */
	public ItemUpdateListingResponse itemUpdateListing(
			ItemUpdateListingRequest itemUpdateListingRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareItemListing(itemUpdateListingRequest);
		return sendItemUpdateListing(params, sessionId);
	}

	protected Map<String, Object> prepareItemListing(
			ItemUpdateListingRequest itemUpdateListingRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将itemUpdateListing请求中的参数添加到params
		params.put(ApiConstants.IID, itemUpdateListingRequest.getIid());
		params.put(ApiConstants.NUM, itemUpdateListingRequest.getNum());
		return params;
	}

	protected ItemUpdateListingResponse sendItemUpdateListing(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_UPDATE_LISTING
						.getMethod(), sessionId, params));
		ItemUpdateListingResponse itemUpdateListingResponse = new ItemUpdateListingResponse(
				response);
		// 平台成功访问
		if (itemUpdateListingResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(itemUpdateListingResponse
						.getBody());
				parseError(itemUpdateListingResponse, json);
				// 访问淘宝成功
				if (itemUpdateListingResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						JSONObject item = items.getJSONObject(0);
						itemUpdateListingResponse.setIid(item
								.getString(ApiConstants.IID));
						try {
							itemUpdateListingResponse.setModified(DateUtil
									.strToDate(item
											.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemUpdateListingResponse;
	}

	@Deprecated
	public ItemUpdateRevokeShowcaseResponse itemUpdateRevokeShowcase(
			ItemUpdateRevokeShowcaseRequest req, String sessionId) throws TaobaoApiException {
		return new ItemUpdateRevokeShowcaseResponse(this.itemRecommendDelete(req, sessionId));
	}

	@Deprecated
	public ItemUpdateShowcaseResponse itemUpdateShowcase(ItemUpdateShowcaseRequest req,
			String sessionId) throws TaobaoApiException {
		return new ItemUpdateShowcaseResponse(this.itemRecommendAdd(req, sessionId));
	}

	@Deprecated
	public ItemCatsResponse itemCatsGetV2(ItemCatsGetV2Request itemCatsGetV2Request)
			throws TaobaoApiException {
		return itemCatsGet(itemCatsGetV2Request);
	}

	@Deprecated
	public ItemPropsResponse itemPropsGetV2(ItemPropsV2Request itemPropsV2Request)
			throws TaobaoApiException {
		return itemPropsGet(itemPropsV2Request);
	}

	public ItemPropValuesResponse itemPropValuesGet(
			ItemPropValuesGetRequest itemPropValuesGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将itemPropsGetRequest请求中的参数添加到params
		params.put(ApiConstants.CID, itemPropValuesGetRequest.getCid());
		params.put(ApiConstants.FIELDS, itemPropValuesGetRequest.getFields());
		params.put(ApiConstants.PVS, itemPropValuesGetRequest.getPvs());
		params.put(ApiConstants.DATETIME, itemPropValuesGetRequest.getDatetime());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMPROPVALUES_GET
						.getMethod(), params));
		ItemPropValuesResponse itemPropValuesResponse = new ItemPropValuesResponse(
				response);
		// 平台访问成功
		if (itemPropValuesResponse.isSuccess()) {
			JSONObject json = null;
			try {
				json = new JSONObject(itemPropValuesResponse.getBody());
				parseError(itemPropValuesResponse, json);
				// 淘宝访问成功
				if (itemPropValuesResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.PROP_VALUES)) {
						JSONArray prop_values = rsp
								.getJSONArray(ApiConstants.PROP_VALUES);
						itemPropValuesResponse
								.setPropValues(TaobaoProductJSONConvert
										.convertJsonArrayToPropValueList(prop_values));
					}
					setTotalResults(rsp, itemPropValuesResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemPropValuesResponse;
	}

	// *********************类目属性部分************************

	public ItemCatsResponse itemCatsGet(ItemCatsGetRequest itemCatsGetRequest) throws TaobaoApiException {
		Map<String, Object> params = prepareItemCatsGet(itemCatsGetRequest);
		return sendItemCatsGet(params, null);
	}

	@Deprecated
	public ItemCatsResponse itemCatsGet(ItemCatsGetRequest itemCatsGetRequest, String sessionId)
			throws TaobaoApiException {
		return itemCatsGet(itemCatsGetRequest);
	}

	protected Map<String, Object> prepareItemCatsGet(ItemCatsGetRequest itemCatsGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, itemCatsGetRequest.getFields());
		params.put(ApiConstants.PARENT_CID, itemCatsGetRequest.getParentCid());
		params.put(ApiConstants.CIDS, itemCatsGetRequest.getCids());
		params.put(ApiConstants.DATETIME, itemCatsGetRequest.getDatetime());
		return params;
	}

	protected ItemCatsResponse sendItemCatsGet(Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMCATS_GET.getMethod(), sessionId, params));
		ItemCatsResponse itemCatsGetResponse = new ItemCatsResponse(response);
		// 平台访问成功
		if (itemCatsGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemCatsGetResponse.getBody());
				parseError(itemCatsGetResponse, json);
				// 淘宝访问成功
				if (itemCatsGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEM_CATS)) {
						JSONArray itemcats = rsp.getJSONArray(ApiConstants.ITEM_CATS);
						itemCatsGetResponse.setItemCats(TaobaoItemJSONConvert
								.convertJsonArrayToItemCatList(itemcats));
					}
					setTotalResults(rsp, itemCatsGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemCatsGetResponse;
	}

	/**
	 * 得到前台商品类目
	 * 
	 * @param itemCatsGetRequest
	 * @return ItemCatsListResponse
	 * @throws TaobaoApiException
	 */
	public ItemCatsListResponse itemCatsListGet(
			ItemCatsListGetRequest itemCatsGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将itemCatsGetRequest请求中的参数添加到params
		params.put(ApiConstants.PARENT_CID, itemCatsGetRequest.getParentCid());
		params.put(ApiConstants.CIDS, itemCatsGetRequest.getCids());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMCATS_LIST_GET
						.getMethod(), params));
		ItemCatsListResponse itemCatsListGetResponse = new ItemCatsListResponse(
				response);
		// 平台访问成功
		if (itemCatsListGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemCatsListGetResponse.getBody());
				parseError(itemCatsListGetResponse, json);
				// 淘宝访问成功
				if (itemCatsListGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEM_CATS)) {
						JSONArray itemcats = rsp
								.getJSONArray(ApiConstants.ITEM_CATS);
						itemCatsListGetResponse
								.setItemCats(TaobaoItemJSONConvert
										.convertJsonArrayToItemCatList(itemcats));
					}
					setTotalResults(rsp, itemCatsListGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemCatsListGetResponse;
	}
	
	public FeaturesGetResponse itemCatFeaturesGet(FeaturesGetRequest req)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将itemCatsGetRequest请求中的参数添加到params
		params.put(ApiConstants.CID, req.getCid());
		params.put(ApiConstants.ATTR_KEYS, req.getAttrKeys());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITECAT_FEATURES_GET
						.getMethod(), params));
		FeaturesGetResponse featuresGetResponse = new FeaturesGetResponse(response);
		
		// 平台访问成功
		if (featuresGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(featuresGetResponse.getBody());
				parseError(featuresGetResponse, json);
				// 淘宝访问成功
				if (featuresGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.Features)) {
						JSONArray features = rsp.getJSONArray(ApiConstants.Features);
						featuresGetResponse
								.setFeatures(TaobaoItemJSONConvert.convertJsonArrayToFeatureList(features));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return featuresGetResponse;
	}

	public ItemPropsResponse itemPropsGet(ItemPropsRequest itemPropsGetRequest) throws TaobaoApiException {
		Map<String, Object> params = prepareItemPropsGet(itemPropsGetRequest);
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMPROPS_GET.getMethod(), params));
		ItemPropsResponse itemPropsGetResponse = new ItemPropsResponse(response);
		// 平台访问成功
		if (itemPropsGetResponse.isSuccess()) {
			JSONObject json = null;
			try {
				json = new JSONObject(itemPropsGetResponse.getBody());
				parseError(itemPropsGetResponse, json);
				// 淘宝访问成功
				if (itemPropsGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEM_PROPS)) {
						JSONArray item_props = rsp.getJSONArray(ApiConstants.ITEM_PROPS);
						itemPropsGetResponse.setItemProps(TaobaoItemJSONConvert
								.convertJSONArrayToItemPropList(item_props));
						if (rsp.has(ApiConstants.LAST_MODIFIELD)) {
							String lastModifled = rsp.getString(ApiConstants.LAST_MODIFIELD);
							if (null != lastModifled) {
								try {
									itemPropsGetResponse.setLastModifled(DateUtil.strToDate(lastModifled));
								} catch (ParseException e) {
									throw new TaobaoApiException(e);
								}
							}
						}
					}
					setTotalResults(rsp, itemPropsGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemPropsGetResponse;
	}

	protected Map<String, Object> prepareItemPropsGet(ItemPropsRequest itemPropsGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.CID, itemPropsGetRequest.getCid());
		params.put(ApiConstants.FIELDS, itemPropsGetRequest.getFields());
		params.put(ApiConstants.PID, itemPropsGetRequest.getPid());
		params.put(ApiConstants.PARENT_PID, itemPropsGetRequest.getParentPid());
		params.put(ApiConstants.IS_KEY_PROP, itemPropsGetRequest.getIsKeyProp());
		params.put(ApiConstants.IS_SALE_PROP, itemPropsGetRequest.getIsSaleProp());
		params.put(ApiConstants.IS_COLOR_PROP, itemPropsGetRequest.getIsColorProp());
		params.put(ApiConstants.IS_ENUM_PROP, itemPropsGetRequest.getIsEnumProp());
		params.put(ApiConstants.IS_INPUT_PROP, itemPropsGetRequest.getIsInputProp());
		params.put(ApiConstants.IS_ITEM_PROP, itemPropsGetRequest.getIsItemProp());
		params.put(ApiConstants.DATETIME, itemPropsGetRequest.getDatetime());
		return params;
	}

	@Deprecated
	public ItemPropsResponse itemPropsGet(ItemPropsRequest itemPropsGetRequest, String sessionId)
			throws TaobaoApiException {
		return itemPropsGet(itemPropsGetRequest);
	}

	/**
	 * 得到前台展示的供买家浏览的商品属性
	 * 
	 * @param itemPropsListGetRequest
	 * @return ItemPropsResponse
	 * @throws TaobaoApiException
	 */
	public ItemPropsResponse itemPropsListGet(
			ItemPropsRequest itemPropsListGetRequest) throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将itemPropsListGetRequest请求中的参数添加到params
		params.put(ApiConstants.CID, itemPropsListGetRequest.getCid());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMPROPS_LIST_GET
						.getMethod(), params));
		ItemPropsResponse itemPropsListGetResponse = new ItemPropsResponse(
				response);
		// 平台访问成功
		if (itemPropsListGetResponse.isSuccess()) {
			JSONObject json = null;
			try {
				json = new JSONObject(itemPropsListGetResponse.getBody());
				parseError(itemPropsListGetResponse, json);
				// 淘宝访问成功
				if (itemPropsListGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEM_PROPS)) {
						JSONArray item_props = rsp
								.getJSONArray(ApiConstants.ITEM_PROPS);
						itemPropsListGetResponse
								.setItemProps(TaobaoItemJSONConvert
										.convertJSONArrayToItemPropList(item_props));
					}
					setTotalResults(rsp, itemPropsListGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemPropsListGetResponse;
	}

	/**
	 * 得到spu
	 * 
	 * @param spuGetRequest
	 * @return SpuGetResponse
	 * @throws TaobaoApiException
	 */
	public SpuGetResponse spuGet(SpuGetRequest spuGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将spuGetRequest请求中的参数添加到params
		params.put(ApiConstants.CID, spuGetRequest.getCid());
		params.put(ApiConstants.FIELDS, spuGetRequest.getFields());
		params.put(ApiConstants.PROPS, spuGetRequest.getProps());
		TaobaoResponse response = this.getFetch()
				.fetch(
						this.getServiceUrl(),
						getTemplateRequest(TaobaoApiMethod.SPU_GET.getMethod(),
								params));
		SpuGetResponse spuGetResponse = new SpuGetResponse(response);
		// 平台访问成功
		if (spuGetResponse.isSuccess()) {
			JSONObject json = null;
			try {
				json = new JSONObject(spuGetResponse.getBody());
				parseError(spuGetResponse, json);
				// 淘宝访问成功
				if (spuGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SPUS)) {
						JSONArray spus = rsp.getJSONArray(ApiConstants.SPUS);
						spuGetResponse.setSpus(TaobaoSpuJSONConvert
								.convertJsonArrayToSpuList(spus));
					}
					setTotalResults(rsp, spuGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return spuGetResponse;
	}

	/**
	 * 得到后台供卖家发布商品用的单个商品属性。
	 * 
	 * @param itemPropGetRequest
	 * @return ItemPropResponse
	 * @throws TaobaoApiException
	 */
	public ItemPropResponse itemPropGet(ItemPropRequest itemPropGetRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将itemPropGetRequest请求中的参数添加到params
		params.put(ApiConstants.CID, itemPropGetRequest.getCid());
		params.put(ApiConstants.PID, itemPropGetRequest.getPid());
		params.put(ApiConstants.CHILD_PATH, itemPropGetRequest.getChildPath());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMPROP_GET.getMethod(),
						sessionId, params));
		ItemPropResponse itemPropGetResponse = new ItemPropResponse(response);
		// 平台访问成功
		if (itemPropGetResponse.isSuccess()) {
			JSONObject json = null;
			try {
				json = new JSONObject(itemPropGetResponse.getBody());
				parseError(itemPropGetResponse, json);
				// 淘宝访问成功
				if (itemPropGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEM_PROPS)) {
						JSONObject item_prop = rsp.getJSONArray(
								ApiConstants.ITEM_PROPS).getJSONObject(0);
						itemPropGetResponse.setItemProp(TaobaoItemJSONConvert
								.convertJsonObjectToItemProp(item_prop));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemPropGetResponse;
	}

	/**
	 * 得到前台展示的供买家浏览的商品属性。
	 * 
	 * @param itemPropListGetRequest
	 * @return ItemPropResponse
	 * @throws TaobaoApiException
	 */
	public ItemPropResponse itemPropListGet(
			ItemPropRequest itemPropListGetRequest) throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将itemPropListGetRequest请求中的参数添加到params
		params.put(ApiConstants.CID, itemPropListGetRequest.getCid());
		params.put(ApiConstants.PID, itemPropListGetRequest.getPid());
		params.put(ApiConstants.CHILD_PATH, itemPropListGetRequest
				.getChildPath());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEMPROP_LIST_GET
						.getMethod(), params));
		ItemPropResponse itemPropGetResponse = new ItemPropResponse(response);
		// 平台访问成功
		if (itemPropGetResponse.isSuccess()) {
			JSONObject json = null;
			try {
				json = new JSONObject(itemPropGetResponse.getBody());
				parseError(itemPropGetResponse, json);
				// 淘宝访问成功
				if (itemPropGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEM_PROPS)) {
						JSONObject item_prop = rsp.getJSONArray(
								ApiConstants.ITEM_PROPS).getJSONObject(0);
						itemPropGetResponse.setItemProp(TaobaoItemJSONConvert
								.convertJsonObjectToItemProp(item_prop));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemPropGetResponse;
	}

	/**
	 * 得到前台展示的店铺类目
	 * 
	 * @param itemPropListGetRequest
	 * @return ItemPropResponse
	 * @throws TaobaoApiException
	 */
	public ShopCatsListGetResponse shopCatsListGet() throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SHOPCATS_LIST_GET
						.getMethod(), params));
		ShopCatsListGetResponse shopCatsListGetResponse = new ShopCatsListGetResponse(
				response);
		// 平台访问成功
		if (shopCatsListGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(shopCatsListGetResponse.getBody());
				parseError(shopCatsListGetResponse, json);
				// 淘宝访问成功
				if (shopCatsListGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SHOP_CATS)) {
						JSONArray shopcats = rsp
								.getJSONArray(ApiConstants.SHOP_CATS);
						shopCatsListGetResponse
								.setShopCats(TaobaoShopJSONConvert
										.convertJsonArrayToShopCatList(shopcats));
					}
					setTotalResults(rsp, shopCatsListGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return shopCatsListGetResponse;
	}

	protected Map<String, Object> prepareSellerCatsListGet(
			SellerCatsListGetRequest request) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.NICK, request.getNick());
		return params;
	}

	/**
	 * 得到前台展示的店铺内卖家自定义商品类目
	 * 
	 * @param sellerCatsListGetRequest
	 * @return SellerCatsListGetResponse
	 * @throws TaobaoApiException
	 */
	public SellerCatsListGetResponse sellerCatsListGet(
			SellerCatsListGetRequest sellerCatsListGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = prepareSellerCatsListGet(sellerCatsListGetRequest);
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SELLERCATS_LIST_GET
						.getMethod(), params));
		SellerCatsListGetResponse sellerCatsListGetResponse = new SellerCatsListGetResponse(
				response);
		// 平台访问成功
		if (sellerCatsListGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(sellerCatsListGetResponse.getBody());
				parseError(sellerCatsListGetResponse, json);
				// 淘宝访问成功
				if (sellerCatsListGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SELLER_CATS)) {
						JSONArray sellercats = rsp
								.getJSONArray(ApiConstants.SELLER_CATS);
						sellerCatsListGetResponse
								.setSellerCats(TaobaoSellerJSONConvert
										.convertJsonArrayToSellerCatList(sellercats));
					}
					setTotalResults(rsp, sellerCatsListGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return sellerCatsListGetResponse;
	}

	// 产品部分

	/**
	 * 获取单个产品
	 * 
	 * @param productGetRequest
	 * @return ProductGetResponse
	 * @throws TaobaoApiException
	 */
	public ProductGetResponse productGet(ProductGetRequest productGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ProductGetRequest.FIELDS, productGetRequest.getFields());
		params.put(ProductGetRequest.PRODUCTID, productGetRequest
				.getProductId());
		params.put(ProductGetRequest.CID, productGetRequest.getCid());
		params.put(ProductGetRequest.PROPS, productGetRequest.getProps());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.PRODUCT_GET.getMethod(),
						params));
		ProductGetResponse productGetResponse = new ProductGetResponse(response);
		// 平台访问成功
		if (productGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(productGetResponse.getBody());
				parseError(productGetResponse, json);
				// 访问淘宝成功
				if (productGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ProductGetRequest.PRODUCT)) {
						JSONArray products = rsp
								.getJSONArray(ProductGetRequest.PRODUCT);
						JSONObject product = products.getJSONObject(0);
						productGetResponse.setProduct(TaobaoProductJSONConvert
								.convertJsonToProduct(product));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return productGetResponse;
	}

	/**
	 * 产品搜索
	 * 
	 * @param productSearchRequest
	 * @return ProductSearchResponse
	 * @throws TaobaoApiException
	 */
	public ProductSearchResponse productSearch(
			ProductSearchRequest productSearchRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ProductSearchRequest.FIELDS, productSearchRequest
				.getFields());
		params.put(ProductSearchRequest.Q, productSearchRequest.getQ());
		params.put(ProductSearchRequest.CID, productSearchRequest.getCid());
		params.put(ProductSearchRequest.PROPS, productSearchRequest.getProps());
		params.put(ApiConstants.PAGE_NO, productSearchRequest.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, productSearchRequest.getPageSize());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.PRODUCTS_SEARCH.getMethod(),
						params));
		ProductSearchResponse productSearchResponse = new ProductSearchResponse(
				response);
		// 平台访问成功
		if (productSearchResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(productSearchResponse.getBody());
				parseError(productSearchResponse, json);
				// 访问淘宝成功
				if (productSearchResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ProductSearchRequest.PRODUCTS)) {
						JSONArray products = rsp
								.getJSONArray(ProductSearchRequest.PRODUCTS);
						productSearchResponse
								.setProduct(TaobaoProductJSONConvert
										.convertJsonArrayToProductList(products));
					}
					setTotalResults(rsp, productSearchResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return productSearchResponse;
	}

	// 交易部分

	/**
	 * 获取单条交易信息，包含支付宝交易号及实付金额
	 * 
	 * @param tradeGetRequest
	 * @return TradeGetResponse
	 * @throws TaobaoApiException
	 */
	public TradeGetResponse tradeGet(TradeGetRequest tradeGetRequest)
			throws TaobaoApiException {
		return tradeGet(tradeGetRequest, null);
	}

	public TradeGetResponse tradeGet(TradeGetRequest tradeGetRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareTradeGet(tradeGetRequest);
		return sendTradeGet(params, sessionId);
	}

	protected TradeGetResponse sendTradeGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TRADE_GET.getMethod(),
						sessionId, params));
		TradeGetResponse tradeGetResponse = new TradeGetResponse(response);
		// 平台成功访问
		if (tradeGetResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(tradeGetResponse.getBody());
				parseError(tradeGetResponse, json);
				// 访问淘宝成功
				if (tradeGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TRADES)) {
						JSONArray trades = rsp
								.getJSONArray(ApiConstants.TRADES);
						JSONObject trade = trades.getJSONObject(0);
						tradeGetResponse.setTrade(TaobaoTradeJSONConvert
								.convertJsonToTrade(trade));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return tradeGetResponse;
	}

	protected Map<String, Object> prepareTradeGet(
			TradeGetRequest tradeGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将tradeGet请求中的参数添加到params
		params.put(ApiConstants.FIELDS, tradeGetRequest.getFields());
		params.put(ApiConstants.TID, tradeGetRequest.getTid());
		return params;
	}

	/**
	 * 搜索交易公开信息
	 * 
	 * @param tradesGetRequest
	 * @return TradesGetResponse
	 * @throws TaobaoApiException
	 */
	public TradesGetResponse tradesGet(TradesGetRequest tradesGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将tradesGetRequest请求中的参数添加到params
		params.put(ApiConstants.IID, tradesGetRequest.getIid());
		params.put(ApiConstants.FIELDS, tradesGetRequest.getFields());
		params.put(ApiConstants.SELLER_NICK, tradesGetRequest.getSellerNick());
		params.put(ApiConstants.PAGE_NO, tradesGetRequest.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, tradesGetRequest.getPageSize());
		params.put(ApiConstants.TYPE, tradesGetRequest.getType());

		return sendTradesGet(params, null, TaobaoApiMethod.TRADES_GET);
	}

	/**
	 * 搜索当前会话用户（做为买家）达成的交易记录
	 * 
	 * @param tradesGetRequest
	 * @return TradesGetResponse
	 * @throws TaobaoApiException
	 */
	public TradesGetResponse tradesBoughtGet(
			TradesBoughtGetRequest tradesRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareTradesBought(tradesRequest);
		return sendTradesGet(params, sessionId,
				TaobaoApiMethod.TRADES_BOUGHT_GET);
	}

	/**
	 * 数据准备，将tradesBoughtGetRequest数据封装为Map对象返回
	 * 
	 * @param tradesBoughtGetRequest
	 * @return Map<String, Object>
	 * @throws
	 */
	protected Map<String, Object> prepareTradesBought(
			TradesBoughtGetRequest tradesBoughtGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将tradesRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, tradesBoughtGetRequest.getFields());
		params.put(ApiConstants.PAGE_NO, tradesBoughtGetRequest.getPageNo());
		params
				.put(ApiConstants.PAGE_SIZE, tradesBoughtGetRequest
						.getPageSize());
		params.put(ApiConstants.START_CREATED, tradesBoughtGetRequest
				.getStartCreated());
		params.put(ApiConstants.END_CREATED, tradesBoughtGetRequest
				.getEndCreated());
		params.put(ApiConstants.TITLE, tradesBoughtGetRequest.getTitle());
		params.put(ApiConstants.STATUS, tradesBoughtGetRequest.getStatus());
		params.put(ApiConstants.SELLER_NICK, tradesBoughtGetRequest
				.getSellerNick());
		params.put(ApiConstants.TYPE, tradesBoughtGetRequest.getType());

		return params;
	}

	/**
	 * 搜索当前会话用户（做为卖家）已卖出的交易数据
	 * 
	 * @param tradesGetRequest
	 * @return TradesGetResponse
	 * @throws TaobaoApiException
	 */
	public TradesGetResponse tradesSoldGet(TradesSoldGetRequest tradesRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareTradesSold(tradesRequest);
		return sendTradesGet(params, sessionId, TaobaoApiMethod.TRADES_SOLD_GET);
	}

	/**
	 * 数据准备，将tradesSoldGetRequest数据封装为Map对象返回
	 * 
	 * @param tradesRequest
	 * @return
	 */
	protected Map<String, Object> prepareTradesSold(
			TradesSoldGetRequest tradesRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将tradesRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, tradesRequest.getFields());
		params.put(ApiConstants.PAGE_NO, tradesRequest.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, tradesRequest.getPageSize());
		params.put(ApiConstants.START_CREATED, tradesRequest.getStartCreated());
		params.put(ApiConstants.END_CREATED, tradesRequest.getEndCreated());
		params.put(ApiConstants.TITLE, tradesRequest.getTitle());
		params.put(ApiConstants.STATUS, tradesRequest.getStatus());
		params.put(ApiConstants.BUYER_NICK, tradesRequest.getBuyerNick());
		params.put(ApiConstants.TYPE, tradesRequest.getType());
		params.put(ApiConstants.RATE_STATUS, tradesRequest.getRateStatus());
		return params;
	}

	public TradesGetResponse tradesSoldIncrementGet(
			TradesSoldIncrementGetRequest req, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareTradesSoldV2(req);
		return sendTradesGet(params, sessionId,
				TaobaoApiMethod.TRADES_SOLD_INCREMENT_GET);
	}

	/**
	 * 数据准备，将tradesSoldGetV2Request数据封装为Map对象返回
	 * 
	 * @param tradesRequest
	 * @return
	 */
	protected Map<String, Object> prepareTradesSoldV2(
			TradesSoldIncrementGetRequest req) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将req请求中的参数添加到params
		params.put(ApiConstants.FIELDS, req.getFields());
		params.put(ApiConstants.PAGE_NO, req.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, req.getPageSize());
		params.put(ApiConstants.STATUS, req.getStatus());
		params.put(ApiConstants.TYPE, req.getType());
		params.put(ApiConstants.START_MODIFIED, req.getStartModified());
		params.put(ApiConstants.END_MODIFIED, req.getEndModified());
		return params;
	}

	/**
	 * 提供： 1、taobao.trades.get 2、taobao.trades.bought.get
	 * 3、taobao.trades.sold.get 4、taobao.trades.sold.increment.get
	 * 
	 * @param params
	 * @param sessionId
	 * @param apiMethod
	 * @return
	 * @throws TaobaoApiException
	 */
	protected TradesGetResponse sendTradesGet(Map<String, Object> params,
			String sessionId, TaobaoApiMethod apiMethod)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(apiMethod.getMethod(), sessionId, params));
		TradesGetResponse tradesGetResponse = new TradesGetResponse(response);
		// 平台访问成功
		if (tradesGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(tradesGetResponse.getBody());
				parseError(tradesGetResponse, json);
				// 淘宝访问成功
				if (tradesGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TRADES)) {
						JSONArray trades = rsp
								.getJSONArray(ApiConstants.TRADES);
						tradesGetResponse.setTrades(TaobaoTradeJSONConvert
								.convertJsonArrayToTradeList(trades));
					}
					setTotalResults(rsp, tradesGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return tradesGetResponse;
	}

	public TradeRateAddResponse tradeRateAdd(
			TradeRateAddRequest tradeRateAddRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将tradeRateAddRequest请求中的参数添加到params
		params.put(ApiConstants.TID, tradeRateAddRequest.getTid());
		params.put(ApiConstants.ORDER_ID, tradeRateAddRequest.getOrderId());
		params.put(ApiConstants.ROLE, tradeRateAddRequest.getRole());
		params.put(ApiConstants.ANONY, tradeRateAddRequest.getAnony());
		params.put(ApiConstants.CONTENT, tradeRateAddRequest.getContent());
		params.put(ApiConstants.RESULT, tradeRateAddRequest.getResult());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TRADERATE_ADD.getMethod(),
						sessionId, params));
		TradeRateAddResponse tradeRateAddResponse = new TradeRateAddResponse(
				response);
		// 平台成功访问
		if (tradeRateAddResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(tradeRateAddResponse.getBody());
				parseError(tradeRateAddResponse, json);
				// 访问淘宝成功
				if (tradeRateAddResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TRADERATES)) {
						JSONArray tradeRates = rsp
								.getJSONArray(ApiConstants.TRADERATES);
						JSONObject tradeRate = tradeRates.getJSONObject(0);
						try {
							tradeRateAddResponse.setCreated(DateUtil
									.strToDate(tradeRate
											.getString(ApiConstants.CREATED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						if (tradeRate.has(ApiConstants.TID)) {
							tradeRateAddResponse.setTid(tradeRate
									.getString(ApiConstants.TID));
						}
						if (tradeRate.has(ApiConstants.ORDER_ID)) {
							tradeRateAddResponse.setOrderId(tradeRate
									.getString(ApiConstants.ORDER_ID));
						}
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return tradeRateAddResponse;
	}

	public TradeRateListAddResponse tradeRateListAdd(
			TradeRateListAddRequest tradeRateListAddRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将tradeRateAddRequest请求中的参数添加到params
		params.put(ApiConstants.TID, tradeRateListAddRequest.getTid());
		params.put(ApiConstants.ROLE, tradeRateListAddRequest.getRole());
		params.put(ApiConstants.ANONY, tradeRateListAddRequest.getAnony());
		params.put(ApiConstants.CONTENT, tradeRateListAddRequest.getContent());
		params.put(ApiConstants.RESULT, tradeRateListAddRequest.getResult());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TRADERATE_LIST_ADD
						.getMethod(), sessionId, params));
		TradeRateListAddResponse tradeRateListAddResponse = new TradeRateListAddResponse(
				response);
		// 平台成功访问
		if (tradeRateListAddResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(tradeRateListAddResponse
						.getBody());
				parseError(tradeRateListAddResponse, json);
				// 访问淘宝成功
				if (tradeRateListAddResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TRADERATES)) {
						JSONArray tradeRates = rsp
								.getJSONArray(ApiConstants.TRADERATES);
						JSONObject tradeRate = tradeRates.getJSONObject(0);
						try {
							tradeRateListAddResponse.setCreated(DateUtil
									.strToDate(tradeRate
											.getString(ApiConstants.CREATED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						tradeRateListAddResponse.setTid(tradeRate
								.getString(ApiConstants.TID));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return tradeRateListAddResponse;
	}

	public TradeRatesGetResponse tradeRatesGet(
			TradeRatesGetRequest tradeRatesGetRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将tradeRatesGetRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, tradeRatesGetRequest.getFields());
		params.put(ApiConstants.ROLE, tradeRatesGetRequest.getRole());
		params.put(ApiConstants.RATE_TYPE, tradeRatesGetRequest.getRateType());
		params.put(ApiConstants.RESULT, tradeRatesGetRequest.getResult());
		params.put(ApiConstants.PAGE_NO, tradeRatesGetRequest.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, tradeRatesGetRequest.getPageSize());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TRADERATES_GET.getMethod(),
						sessionId, params));
		TradeRatesGetResponse tradeRatesGetResponse = new TradeRatesGetResponse(
				response);
		// 平台访问成功
		if (tradeRatesGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(tradeRatesGetResponse.getBody());
				parseError(tradeRatesGetResponse, json);
				// 访问淘宝成功
				if (tradeRatesGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TRADERATES)) {
						JSONArray tradeRates = rsp
								.getJSONArray(ApiConstants.TRADERATES);
						tradeRatesGetResponse
								.setTradeRates(TaobaoTradeJSONConvert
										.convertJsonArrayToTradeRateList(tradeRates));
					}
					setTotalResults(rsp, tradeRatesGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return tradeRatesGetResponse;
	}
	
	public TradeConfirmFeeGetResponse tradeConfirmFeeGet(
			TradeConfirmFeeGetRequest req, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareTradeConfirmFeeGet(req);
		return sendTradeConfirmFeeGet(params, sessionId);
	}

	protected Map<String, Object> prepareTradeConfirmFeeGet(
			TradeConfirmFeeGetRequest req) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.TID, req.getTid());
		params.put(ApiConstants.IS_DETAIL, req.getIsDetail());
		return params;
	}
	
	protected TradeConfirmFeeGetResponse sendTradeConfirmFeeGet(
			Map<String, Object> params, String sessionId) throws TaobaoApiException {
		TaobaoResponse taobaoResponse = this.getFetch().fetch(
				this.getServiceUrl(), getTemplateRequest(TaobaoApiMethod.TRADE_CONFIRMFEE_GET.getMethod(), sessionId, params));
		
		TradeConfirmFeeGetResponse response = new TradeConfirmFeeGetResponse(taobaoResponse);
		
		// 平台访问成功
		if (response.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(response.getBody());
				parseError(response, json);
				// 访问淘宝成功
				if (response.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.CONFIRM_FEES)) {
						json = rsp.getJSONArray(ApiConstants.CONFIRM_FEES).getJSONObject(0);
						TradeConfirmFee confirmFee = new TradeConfirmFee();
						if (json.has(ApiConstants.CONFIRM_FEE))
							confirmFee.setConfirmFee(json.getString(ApiConstants.CONFIRM_FEE));
						if (json.has(ApiConstants.CONFIRM_POST_FEE))
							confirmFee.setConfirmPostFee(json.getString(ApiConstants.CONFIRM_POST_FEE));
						if (json.has(ApiConstants.IS_LAST_DETAIL_ORDER))
							confirmFee.setIsLastDetailOrder(json.getString(ApiConstants.IS_LAST_DETAIL_ORDER));
						
						response.setConfirmFee(confirmFee);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return response;
	}

	// 用户部分

	/**
	 * 获取单个用户信息
	 * 
	 * @param userGetRequest
	 * @return UserGetResponse
	 * @throws TaobaoApiException
	 */
	public UserGetResponse userGet(UserGetRequest userGetRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareUserGet(userGetRequest);
		return sendUserGet(params, sessionId);
	}

	protected Map<String, Object> prepareUserGet(UserGetRequest userGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将userGetRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, userGetRequest.getFields());
		params.put(ApiConstants.NICK, userGetRequest.getNick());
		return params;
	}

	protected UserGetResponse sendUserGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.USER_GET.getMethod(),
						sessionId, params));
		UserGetResponse userGetResponse = new UserGetResponse(response);
		// 平台访问成功
		if (userGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(userGetResponse.getBody());
				parseError(userGetResponse, json);
				// 淘宝访问成功
				if (userGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.USERS)) {
						JSONArray users = rsp.getJSONArray(ApiConstants.USERS);
						JSONObject user = users.getJSONObject(0);
						userGetResponse.setUser(TaobaoUserJSONConvert
								.convertJsonToUser(user));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return userGetResponse;
	}

	public UserGetResponse userGet(UserGetRequest userGetRequest)
			throws TaobaoApiException {
		return this.userGet(userGetRequest, null);
	}
	
	public UserDetailGetResponse userDetail(
			UserDetailGetRequest userDetailGetRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, userDetailGetRequest.getFields());
		params.put(ApiConstants.NICK, userDetailGetRequest.getNick());
		return sendUserDetailGet(params, sessionId);
	}
	
	protected UserDetailGetResponse sendUserDetailGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.USER_DETAIL_GET.getMethod(),sessionId, params));
		UserDetailGetResponse userDetailGetResponse = new UserDetailGetResponse(response);
		// 平台访问成功
		if (userDetailGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(userDetailGetResponse.getBody());
				parseError(userDetailGetResponse, json);
				// 淘宝访问成功
				if (userDetailGetResponse.isSuccess()) { 
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.USERS)) {
						JSONArray userDetails = rsp.getJSONArray(ApiConstants.USERS);
						JSONObject userDetail = userDetails.getJSONObject(0);
						userDetailGetResponse.setUserDetail(TaobaoUserJSONConvert
								.convertJsonToUser(userDetail));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return userDetailGetResponse;
	}
	
	/**
	 * 搜索用户信息
	 * 
	 * @param usersGetRequest
	 * @return UsersGetResponse
	 * @throws TaobaoApiException
	 */
	public UsersGetResponse usersGet(UsersGetRequest usersGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将usersGetRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, usersGetRequest.getFields());
		params.put(ApiConstants.NICKS, usersGetRequest.getNicks());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.USERS_GET.getMethod(),
						params));
		UsersGetResponse usersGetResponse = new UsersGetResponse(response);
		// 平台访问成功
		if (usersGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(usersGetResponse.getBody());
				parseError(usersGetResponse, json);
				// 淘宝访问成功
				if (usersGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.USERS)) {
						JSONArray users = rsp.getJSONArray(ApiConstants.USERS);
						usersGetResponse.setUsers(TaobaoUserJSONConvert
								.convertJsonArrayToUserList(users));
					}
					setTotalResults(rsp, usersGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return usersGetResponse;
	}

	// 店铺部分

	/**
	 * 此接口用于获取卖家店铺基本信息
	 * 
	 * @param usersGetRequest
	 * @return UsersGetResponse
	 * @throws TaobaoApiException
	 */
	public ShopGetResponse shopGet(ShopGetRequest shopGetRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareShopGet(shopGetRequest);
		return sendShopGet(params, sessionId);
	}

	public ShopGetResponse shopGet(ShopGetRequest shopGetRequest)
			throws TaobaoApiException {
		return this.shopGet(shopGetRequest, null);
	}

	protected Map<String, Object> prepareShopGet(ShopGetRequest shopGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将shopGetRequest请求中的参数添加到params
		params.put(ApiConstants.NICK, shopGetRequest.getNick());
		params.put(ApiConstants.FIELDS, shopGetRequest.getFields());
		return params;
	}

	protected ShopGetResponse sendShopGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SHOP_GET.getMethod(),
						sessionId, params));
		ShopGetResponse shopGetResponse = new ShopGetResponse(response);
		// 平台访问成功
		if (shopGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(shopGetResponse.getBody());
				parseError(shopGetResponse, json);
				// 淘宝访问成功
				if (shopGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SHOPS)) {
						JSONArray shops = rsp.getJSONArray(ApiConstants.SHOPS);
						JSONObject shop = shops.getJSONObject(0);
						shopGetResponse.setShop(TaobaoShopJSONConvert
								.convertJsonToShop(shop));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return shopGetResponse;
	}

	protected Map<String, Object> prepareShopUpdate(
			ShopUpdateRequest shopUpdateRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.TITLE, shopUpdateRequest.getTitle());
		params.put(ApiConstants.DESC, shopUpdateRequest.getDesc());
		params.put(ApiConstants.BULLETIN, shopUpdateRequest.getBulletin());
		return params;
	}

	/**
	 * 更新店铺的标题、公告及介绍
	 * 
	 * @param shopUpdateRequest
	 * @return ShopUpdateResponse
	 * @throws TaobaoApiException
	 */
	public ShopUpdateResponse shopUpdate(ShopUpdateRequest shopUpdateRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareShopUpdate(shopUpdateRequest);
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SHOP_UPDATE.getMethod(),
						sessionId, params));
		ShopUpdateResponse shopUpdateResponse = new ShopUpdateResponse(response);
		// 平台成功访问
		if (shopUpdateResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(shopUpdateResponse.getBody());
				parseError(shopUpdateResponse, json);
				// 访问淘宝成功
				if (shopUpdateResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SHOPS)) {
						JSONArray shops = rsp.getJSONArray(ApiConstants.SHOPS);
						JSONObject shop = shops.getJSONObject(0);
						shopUpdateResponse.setShop(TaobaoShopJSONConvert
								.convertJsonToShop(shop));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return shopUpdateResponse;
	}

	/**
	 * 获取剩余的橱窗推荐数量
	 * 
	 * @param shopShowcaseRemainCountRequest
	 * @return ShopShowcaseRemainCountRequest
	 * @throws TaobaoApiException
	 */
	public ShopShowcaseRemainCountResponse shopShowcaseRemainCount(
			ShopShowcaseRemainCountRequest shopShowcaseRemainCountRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		return sendShopShowcaseRemainCount(params, sessionId);
	}

	protected ShopShowcaseRemainCountResponse sendShopShowcaseRemainCount(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SHOP_SHOWCASE_REMAINCOUNT
						.getMethod(), sessionId, params));
		ShopShowcaseRemainCountResponse shopShowcaseRemainCountResponse = new ShopShowcaseRemainCountResponse(
				response);
		// 平台成功访问
		if (shopShowcaseRemainCountResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(
						shopShowcaseRemainCountResponse.getBody());
				parseError(shopShowcaseRemainCountResponse, json);
				// 访问淘宝成功
				if (shopShowcaseRemainCountResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SHOPS)) {
						JSONArray shops = rsp.getJSONArray(ApiConstants.SHOPS);
						JSONObject shop = shops.getJSONObject(0);
						try {
							shopShowcaseRemainCountResponse
									.setRemainShowcase(Integer
											.parseInt(shop
													.getString(ApiConstants.REMAIN_COUNT)));
						} catch (JSONException e) {
							throw new TaobaoApiException(e);
						}
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}

		return shopShowcaseRemainCountResponse;
	}

	// ===================================物流部分=======================================================
	protected Map<String, Object> prepareLogisticsOrderGet(LogisticsOrdersGetRequest req) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, req.getFields());
		params.put(ApiConstants.TID, req.getTid());
		params.put(ApiConstants.BUYER_NICK, req.getBuyerNick());
		params.put(ApiConstants.STATUS, req.getStatus());
		params.put(ApiConstants.RECEIVER_NAME, req.getReceiverName());
		params.put(ApiConstants.START_CREATED, req.getStartCreated());
		params.put(ApiConstants.END_CREATED, req.getEndCreated());
		params.put(ApiConstants.ITEM_TITLE, req.getItemTitle());
		params.put(ApiConstants.FREIGHT_PAYER, req.getFreightPayer());
		params.put(ApiConstants.TYPE, req.getType());
		params.put(ApiConstants.PAGE_NO, req.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, req.getPageSize());
		params.put(ApiConstants.SELLER_CONFIRM, req.getSellerConfirm());
		return params;
	}

	public ShippingsSendGetResponse shippingsSendGet(ShippingsSendGetRequest req, String sessionId)
			throws TaobaoApiException {
		return new ShippingsSendGetResponse(this.logisticsOrdersGet(req, sessionId));
	}

	public LogisticsOrdersGetResponse logisticsOrdersGet(LogisticsOrdersGetRequest request,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareLogisticsOrderGet(request);
		return getLogisticsOrders(params, sessionId);
	}

	protected LogisticsOrdersGetResponse getLogisticsOrders(Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.LOGISTICS_ORDERS_GET.getMethod(), sessionId, params));
		LogisticsOrdersGetResponse logr = new LogisticsOrdersGetResponse(response);
		// 平台访问成功
		if (logr.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(logr.getBody());
				parseError(logr, json);
				// 访问淘宝成功
				if (logr.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SHIPPINGS)) {
						JSONArray shippings = rsp.getJSONArray(ApiConstants.SHIPPINGS);
						logr.setShippings(TaobaoShippingJSONConvert
								.convertJsonArrayToShippingList(shippings));
					}
					setTotalResults(rsp, logr);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return logr;
	}

	@Deprecated
	public ShippingsSendFullInfoGetResponse shippingsSendFullInfoGet(
			ShippingsSendFullInfoGetRequest req, String sessionId) throws TaobaoApiException {
		return new ShippingsSendFullInfoGetResponse(this.logisticsOrdersDetailGet(req, sessionId));
	}

	public LogisticsOrdersDetailGetResponse logisticsOrdersDetailGet(
			LogisticsOrdersDetailGetRequest req, String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareLogisticsOrderGet(req);
		return getLogisticsOrdersDetail(params, sessionId);
	}

	protected LogisticsOrdersDetailGetResponse getLogisticsOrdersDetail(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.LOGISTICS_ORDERS_DETAIL_GET.getMethod(), sessionId, params));
		LogisticsOrdersDetailGetResponse lodgr = new LogisticsOrdersDetailGetResponse(response);
		// 平台访问成功
		if (lodgr.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(lodgr.getBody());
				parseError(lodgr, json);
				// 访问淘宝成功
				if (lodgr.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SHIPPINGS)) {
						JSONArray shippings = rsp.getJSONArray(ApiConstants.SHIPPINGS);
						lodgr.setShippings(TaobaoShippingJSONConvert
								.convertJsonArrayToShippingList(shippings));
					}
					setTotalResults(rsp, lodgr);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return lodgr;
	}

	public AreasGetResponse areasGet(AreasGetRequest request)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, request.getField());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.AREAS_GET.getMethod(),
						params));
		AreasGetResponse areasGetResponse = new AreasGetResponse(response);
		// 平台访问成功
		if (areasGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(areasGetResponse.getBody());
				parseError(areasGetResponse, json);
				// 访问淘宝成功
				if (areasGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.AREAS)) {
						JSONArray areas = rsp.getJSONArray(ApiConstants.AREAS);
						areasGetResponse.setAreas(TaobaoShippingJSONConvert
								.convertJsonArrayToAreaList(areas));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return areasGetResponse;
	}

	@Deprecated
	public LogisticCompaniesGetResponse logisticCompaniesGet(LogisticCompaniesGetRequest request)
			throws TaobaoApiException {
		return new LogisticCompaniesGetResponse(this.logisticsCompaniesGet(request));
	}

	public LogisticsCompaniesGetResponse logisticsCompaniesGet(LogisticsCompaniesGetRequest request)
			throws TaobaoApiException {
		Map<String, Object> params = prepareLogisticsCompaniesGet(request);
		return getLogisticsCompanies(params);
	}

	protected LogisticsCompaniesGetResponse getLogisticsCompanies(Map<String, Object> params)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
						getTemplateRequest(TaobaoApiMethod.LOGISTICS_COMPPANIES_GET_NEW.getMethod(), params));
		LogisticsCompaniesGetResponse lcgr = new LogisticsCompaniesGetResponse(response);
		// 平台访问成功
		if (lcgr.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(lcgr.getBody());
				parseError(lcgr, json);
				// 访问淘宝成功
				if (lcgr.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.LOGISTICS_COMPANY)) {
						JSONArray jsonArray = rsp.getJSONArray(ApiConstants.LOGISTICS_COMPANY);
						lcgr.setLogisticCompanies(TaobaoShippingJSONConvert
								.convertJsonArrayToLogisticCompanyList(jsonArray));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return lcgr;
	}

	protected Map<String, Object> prepareLogisticsCompaniesGet(LogisticsCompaniesGetRequest request) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, request.getFields());
		params.put(ApiConstants.IS_RECOMMENTED, request.getIsRecommended());
		params.put(ApiConstants.ORDER_MODE, request.getOrderMode());
		return params;
	}

	public DeliverySendResponse deliverySend(DeliverySendRequest request,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareDeliverySend(request);
		return sendDeliverySend(params, sessionId);
	}

	protected DeliverySendResponse sendDeliverySend(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.DELIVERY_SEND.getMethod(),
						sessionId, params));
		DeliverySendResponse deliverySendResponse = new DeliverySendResponse(
				response);
		if (deliverySendResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(deliverySendResponse.getBody());
				parseError(deliverySendResponse, json);
				// 访问淘宝成功
				if (deliverySendResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SHIPPINGS)) {
						JSONArray shipping = rsp
								.getJSONArray(ApiConstants.SHIPPINGS);
						Shipping deliverySens = TaobaoShippingJSONConvert
								.convertJsonToShippingDeliverySend(shipping
										.getJSONObject(0));
						deliverySendResponse.setDeliverSuccess(deliverySens
								.isSuccess());
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return deliverySendResponse;
	}

	protected Map<String, Object> prepareDeliverySend(
			DeliverySendRequest deliverySendRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.TID, deliverySendRequest.getTid());
		// params.put(ApiConstants.APP_IP, deliverySendRequest.getAppIp());
		params.put(ApiConstants.COMPANY_CODE, deliverySendRequest
				.getCompanyCode());
		params.put(ApiConstants.OUT_SID, deliverySendRequest.getOutSid());
		params.put(ApiConstants.SELLER_NAME, deliverySendRequest
				.getSellerName());
		params.put(ApiConstants.SELLER_AREA_ID, deliverySendRequest
				.getSellerAreaId());
		params.put(ApiConstants.SELLER_ADDRESS, deliverySendRequest
				.getSellerAddress());
		params.put(ApiConstants.SELLER_ZIP, deliverySendRequest.getSellerZip());
		params.put(ApiConstants.SELLER_PHONE, deliverySendRequest
				.getSellerPhone());
		params.put(ApiConstants.SELLER_MOBILE, deliverySendRequest
				.getSellerMobile());
		params.put(ApiConstants.MEMO, deliverySendRequest.getMemo());
		params.put(ApiConstants.DELIVERY_SEND_TYPE, deliverySendRequest.getOrderType());
		return params;
	}

	// ======================================邮费模板=========================================

	public PostageGetResponse postageGet(PostageGetRequest postageGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将postageGetRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, postageGetRequest.getFields());
		params.put(ApiConstants.POSTAGE_ID, postageGetRequest.getPostageId());
		params.put(ApiConstants.NICK, postageGetRequest.getNick());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.POSTAGE_GET.getMethod(),
						params));
		PostageGetResponse postageGetResponse = new PostageGetResponse(response);
		if (postageGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(postageGetResponse.getBody());
				parseError(postageGetResponse, json);
				// 访问淘宝成功
				if (postageGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.POSTAGES)) {
						JSONArray postages = rsp
								.getJSONArray(ApiConstants.POSTAGES);
						JSONObject postage = postages.getJSONObject(0);
						postageGetResponse.setPostage(TaobaoPostageJSONConvert
								.convertJsonToPostage(postage));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return postageGetResponse;
	}

	/**
	 * 邮费模板
	 * 
	 * @param postageGetRequest
	 * @return PostagesGetRequest
	 * @throws TaobaoApiException
	 */
	public PostagesGetResponse postagesGet(
			PostagesGetRequest postageGetRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = preparePostageGet(postageGetRequest);
		return sendPostagesGet(params, sessionId);
	}

	protected Map<String, Object> preparePostageGet(
			PostagesGetRequest postageGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将postageGetRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, postageGetRequest.getFields());
		return params;
	}

	protected PostagesGetResponse sendPostagesGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.POSTAGES_GET.getMethod(),
						sessionId, params));
		PostagesGetResponse postagesGetResponse = new PostagesGetResponse(
				response);
		if (postagesGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(postagesGetResponse.getBody());
				parseError(postagesGetResponse, json);
				// 访问淘宝成功
				if (postagesGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.POSTAGES)) {
						JSONArray postages = rsp
								.getJSONArray(ApiConstants.POSTAGES);
						postagesGetResponse
								.setPostages(TaobaoPostageJSONConvert
										.convertJsonArrayToPostageList(postages));
					}
					setTotalResults(rsp, postagesGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return postagesGetResponse;
	}

	public PostageAddResponse postageAdd(PostageAddRequest request,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = preparePostageAdd(request);

		return sendPostageAdd(params, sessionId);
	}

	protected PostageAddResponse sendPostageAdd(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.POSTAGE_ADD.getMethod(),
						sessionId, params));
		PostageAddResponse postageAddResonse = new PostageAddResponse(response);
		if (postageAddResonse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(postageAddResonse.getBody());
				parseError(postageAddResonse, json);
				// 访问淘宝成功
				if (postageAddResonse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.POSTAGES)) {
						JSONArray items = rsp
								.getJSONArray(ApiConstants.POSTAGES);
						JSONObject postageJson = items.getJSONObject(0);
						Postage postage = new Postage();
						postage.setPostageId(postageJson
								.getString(ApiConstants.POSTAGE_ID));
						try {
							postage.setCreated(DateUtil.strToDate(postageJson
									.getString(ApiConstants.CREATED)));
						} catch (ParseException e) {
							e.printStackTrace();
						}
						postageAddResonse.setPostage(postage);
					}
				}

			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return postageAddResonse;
	}

	protected Map<String, Object> preparePostageAdd(PostageAddRequest request) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.NAME, request.getName());
		params.put(ApiConstants.MEMO, request.getMemo());
		params.put(ApiConstants.POST_PRICE, request.getPostPrice());
		params.put(ApiConstants.POST_INCREASE, request.getPostIncrease());
		params.put(ApiConstants.EXPRESS_PRICE, request.getExpressPrice());
		params.put(ApiConstants.EXPRESS_INCREASE, request.getExpressIncrease());
		params.put(ApiConstants.EMS_PRICE, request.getEmsPrice());
		params.put(ApiConstants.EMS_INCREASE, request.getEmsIncrease());
		params
				.put(ApiConstants.POSTAGE_MODE_TYPE, request
						.getPostageModeType());
		params
				.put(ApiConstants.POSTAGE_MODE_DEST, request
						.getPostageModeDest());
		params.put(ApiConstants.POSTAGE_MODE_PRICE, request
				.getPostageModePrice());
		params.put(ApiConstants.POSTAGE_MODE_INCREASE, request
				.getPostageModeIncrease());
		return params;
	}

	public PostageUpdateResponse postageUpdate(PostageUpdateRequest request,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = preparePostageUpdate(request);
		return sendPostageUpdate(params, sessionId);
	}

	protected PostageUpdateResponse sendPostageUpdate(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.POSTAGE_UPDATE.getMethod(),
						sessionId, params));
		PostageUpdateResponse postageUpdateResonse = new PostageUpdateResponse(
				response);
		if (postageUpdateResonse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(postageUpdateResonse.getBody());
				parseError(postageUpdateResonse, json);
				// 访问淘宝成功
				if (postageUpdateResonse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.POSTAGES)) {
						JSONArray items = rsp
								.getJSONArray(ApiConstants.POSTAGES);
						JSONObject postageJson = items.getJSONObject(0);
						Postage postage = new Postage();
						postage.setPostageId(postageJson
								.getString(ApiConstants.POSTAGE_ID));
						try {
							postage.setModified(DateUtil.strToDate(postageJson
									.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							e.printStackTrace();
						}
						postageUpdateResonse.setPostage(postage);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return postageUpdateResonse;
	}

	protected Map<String, Object> preparePostageUpdate(
			PostageUpdateRequest request) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.POSTAGE_ID, request.getPostage_id());
		params.put(ApiConstants.NAME, request.getName());
		params.put(ApiConstants.MEMO, request.getMemo());
		params.put(ApiConstants.POST_PRICE, request.getPostPrice());
		params.put(ApiConstants.POST_INCREASE, request.getPostIncrease());
		params.put(ApiConstants.EXPRESS_PRICE, request.getExpressPrice());
		params.put(ApiConstants.EXPRESS_INCREASE, request.getExpressIncrease());
		params.put(ApiConstants.EMS_PRICE, request.getEmsPrice());
		params.put(ApiConstants.EMS_INCREASE, request.getEmsIncrease());
		params
				.put(ApiConstants.POSTAGE_MODE_TYPE, request
						.getPostageModeType());
		params
				.put(ApiConstants.POSTAGE_MODE_DEST, request
						.getPostageModeDest());
		params.put(ApiConstants.POSTAGE_MODE_PRICE, request
				.getPostageModePrice());
		params.put(ApiConstants.POSTAGE_MODE_INCREASE, request
				.getPostageModeIncrease());
		params.put(ApiConstants.POSTAGE_MODE_ID, request.getPostageModeId());
		params.put(ApiConstants.POSTAGE_MODE_OPTTYPE, request.getPostageModeOpttype());
		return params;
	}
	
	public PostageDeleteResponse postageDelete(PostageDeleteRequest request,String sessionId) throws TaobaoApiException {
		Map<String, Object> params = preparePostageDelete(request);
		return sendPostageDelete(params, sessionId);
	}
	
	protected Map<String, Object> preparePostageDelete(PostageDeleteRequest request) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.POSTAGE_ID, request.getPostageId());
		return params;
	}
	
	protected PostageDeleteResponse sendPostageDelete(Map<String, Object> params, String sessionId) throws TaobaoApiException{
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.POSTAGE_DELETE.getMethod(),
						sessionId, params));
		PostageDeleteResponse postageDeleteResponse = new PostageDeleteResponse(	response);
		if (postageDeleteResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(postageDeleteResponse.getBody());
				parseError(postageDeleteResponse, json);
				// 访问淘宝成功
				if (postageDeleteResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.POSTAGES)) {
						JSONArray items = rsp
								.getJSONArray(ApiConstants.POSTAGES);
						JSONObject postageJson = items.getJSONObject(0);
						Postage postage = new Postage();
						postage.setPostageId(postageJson.getString(ApiConstants.POSTAGE_ID));
						try {
							postage.setCreated(DateUtil.strToDate(postageJson.getString(ApiConstants.CREATED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						postageDeleteResponse.setPostage(postage);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return postageDeleteResponse;
	}
	// *******************库存部分*******************************

	/**
	 * 添加库存
	 * 
	 * @param postageGetRequest
	 * @return PostagesGetRequest
	 * @throws TaobaoApiException
	 */
	public SkuAddResponse skuAdd(SkuAddRequest skuAddRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareSkuAdd(skuAddRequest);
		return sendSkuAdd(params, sessionId);
	}

	protected Map<String, Object> prepareSkuAdd(SkuAddRequest skuAddRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.IID, skuAddRequest.getIid());
		params.put(ApiConstants.PROPERTIES, skuAddRequest.getProperties());
		params.put(ApiConstants.QUANTITY, skuAddRequest.getQuantity());
		params.put(ApiConstants.PRICE, skuAddRequest.getPrice());
		params.put(ApiConstants.OUTER_ID, skuAddRequest.getOuterId());
		params.put(ApiConstants.LANG, skuAddRequest.getLang());
		return params;
	}

	protected SkuAddResponse sendSkuAdd(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_SKU_ADD.getMethod(),
						sessionId, params));
		SkuAddResponse skuAddResponse = new SkuAddResponse(response);
		if (skuAddResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(skuAddResponse.getBody());
				parseError(skuAddResponse, json);
				if (skuAddResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SKUS)) {
						JSONArray skus = rsp.getJSONArray(ApiConstants.SKUS);
						JSONObject sku = skus.getJSONObject(0);
						Sku addSku = new Sku();
						addSku.setIid(sku.getString(ApiConstants.IID));
						try {
							addSku.setCreated(DateUtil.strToDate(sku
									.getString(ApiConstants.CREATED)));
						} catch (ParseException e) {
							e.printStackTrace();
						}
						skuAddResponse.setSku(addSku);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return skuAddResponse;
	}

	/**
	 * 获取库存量
	 * 
	 * @param postageGetRequest
	 * @return PostagesGetRequest
	 * @throws TaobaoApiException
	 */
	public SkuGetResponse skuGet(SkuGetRequest skuGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = prepareSkuGet(skuGetRequest);
		return sendSkuGet(params);
	}

	protected Map<String, Object> prepareSkuGet(SkuGetRequest skuGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.SKU_ID, skuGetRequest.getSkuId());
		params.put(ApiConstants.NICK, skuGetRequest.getNick());
		params.put(ApiConstants.FIELDS, skuGetRequest.getFields());
		return params;
	}

	protected SkuGetResponse sendSkuGet(Map<String, Object> params)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_SKU_GET.getMethod(),
						params));
		SkuGetResponse skuGetResponse = new SkuGetResponse(response);
		if (skuGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(skuGetResponse.getBody());
				parseError(skuGetResponse, json);
				if (skuGetResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SKUS)) {
						JSONArray skus = rsp.getJSONArray(ApiConstants.SKUS);
						JSONObject sku = skus.getJSONObject(0);
						skuGetResponse.setSku(TaobaoSkuJSONConvert
								.convertJsonToSku(sku));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return skuGetResponse;
	}

	/**
	 * 更新库存信息
	 * 
	 * @param skuUpdateRequest
	 * @return SkuUpdateResponse
	 * @throws TaobaoApiException
	 */
	public SkuUpdateResponse skuUpdate(SkuUpdateRequest skuUpdateRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareSkuUpdate(skuUpdateRequest);
		return sendSkuUpdate(params, sessionId);
	}

	protected Map<String, Object> prepareSkuUpdate(
			SkuUpdateRequest skuUpdateRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.IID, skuUpdateRequest.getIid());
		params.put(ApiConstants.PROPERTIES, skuUpdateRequest.getProperties());
		params.put(ApiConstants.QUANTITY, skuUpdateRequest.getQuantity());
		params.put(ApiConstants.PRICE, skuUpdateRequest.getPrice());
		params.put(ApiConstants.OUTER_ID, skuUpdateRequest.getOuterId());
		params.put(ApiConstants.LANG, skuUpdateRequest.getLang());
		params.put(ApiConstants.SKU_ID, skuUpdateRequest.getSkuId());
		return params;
	}

	protected SkuUpdateResponse sendSkuUpdate(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_SKU_UPDATE.getMethod(),
						sessionId, params));
		SkuUpdateResponse skuUpdateResponse = new SkuUpdateResponse(response);
		if (skuUpdateResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(skuUpdateResponse.getBody());
				parseError(skuUpdateResponse, json);
				if (skuUpdateResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SKUS)) {
						JSONArray skus = rsp.getJSONArray(ApiConstants.SKUS);
						JSONObject sku = skus.getJSONObject(0);
						Sku updatedSku = new Sku();
						updatedSku.setIid(sku.getString(ApiConstants.IID));
						try {
							updatedSku.setModified(DateUtil.strToDate(sku
									.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							e.printStackTrace();
						}
						skuUpdateResponse.setSku(updatedSku);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return skuUpdateResponse;
	}

	/**
	 * 批量获取库存量
	 * 
	 * @param postageGetRequest
	 * @return PostagesGetRequest
	 * @throws TaobaoApiException
	 */
	public SkusGetResponse skusGet(SkusGetRequest skusGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = prepareSkuUpdate(skusGetRequest);
		return sendSkusGet(params);
	}

	protected Map<String, Object> prepareSkuUpdate(SkusGetRequest skusGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.IIDS, skusGetRequest.getIids());
		params.put(ApiConstants.FIELDS, skusGetRequest.getFields());
		params.put(ApiConstants.NICK, skusGetRequest.getNick());
		return params;
	}

	protected SkusGetResponse sendSkusGet(Map<String, Object> params)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_SKUS_GET.getMethod(),
						params));
		SkusGetResponse skusGetResponse = new SkusGetResponse(response);
		if (skusGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(skusGetResponse.getBody());
				parseError(skusGetResponse, json);
				if (skusGetResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SKUS)) {
						JSONArray skus = rsp.getJSONArray(ApiConstants.SKUS);
						skusGetResponse.setSkus(TaobaoSkuJSONConvert
								.convertJsonArrayToSkuList(skus));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return skusGetResponse;
	}

	public ItemJointImgResponse itemJointImg(
			ItemJointImgRequest itemJointImgRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params
				.put(ApiConstants.ITEMIMG_ID, itemJointImgRequest
						.getItemImgId());
		params.put(ApiConstants.IID, itemJointImgRequest.getIid());
		params.put(ApiConstants.POSITION, itemJointImgRequest.getPosition());
		params.put(ApiConstants.ISMAJOR, itemJointImgRequest.isMajor());
		params.put(ApiConstants.URL, itemJointImgRequest.getUrl());
		TaobaoResponse taobaoResponse =  this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.ITEM_JOINT_IMG
							.getMethod(), sessionId, params));
		 ItemJointImgResponse itemJointImgResponse=new ItemJointImgResponse(taobaoResponse);
		if (itemJointImgResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemJointImgResponse.getBody());
				parseError(itemJointImgResponse, json);
				if (itemJointImgResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMIMGS)) {
						JSONArray itemImgs = rsp
								.getJSONArray(ApiConstants.ITEMIMGS);
						JSONObject itemImg = itemImgs.getJSONObject(0);
						ItemImg uploadItemImg = new ItemImg();
						uploadItemImg.setItemimgId(itemImg
								.getString(ApiConstants.ITEMIMG_ID));
						uploadItemImg.setUrl(itemImg
								.getString(ApiConstants.URL));
						uploadItemImg.setCreated(itemImg
								.getString(ApiConstants.CREATED));
						itemJointImgResponse.setItemImg(uploadItemImg);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemJointImgResponse;
	}
	public ItemJointPropimgResponse itemJointPropimg(
			ItemJointPropimgRequest itemJointPropimgRequest, String sessionId)
			throws TaobaoApiException{
		Map<String, Object> params = new HashMap<String, Object>();
		params
				.put(ApiConstants.PROPIMG_ID, itemJointPropimgRequest
						.getPropImgId());
		params.put(ApiConstants.IID, itemJointPropimgRequest.getIid());
		params.put(ApiConstants.PROPERTIES, itemJointPropimgRequest
				.getProperties());
		params.put(ApiConstants.POSITION, itemJointPropimgRequest.getPosition());
		params.put(ApiConstants.URL, itemJointPropimgRequest.getUrl());
		TaobaoResponse taobaoResponse = this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.ITEM_JOINT_PROPIMG
							.getMethod(), sessionId, params));
		ItemJointPropimgResponse  itemJointPropimgResponse=new ItemJointPropimgResponse(taobaoResponse);
		if (itemJointPropimgResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemJointPropimgResponse.getBody());
				parseError(itemJointPropimgResponse, json);
				if (itemJointPropimgResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.PROPIMGS)) {
						JSONArray propimgs = rsp
								.getJSONArray(ApiConstants.PROPIMGS);
						JSONObject propimg = propimgs.getJSONObject(0);
						PropImg uploadPropImg = new PropImg();
						uploadPropImg.setPropimg_id(propimg
								.getString(ApiConstants.PROPIMG_ID));
						uploadPropImg.setUrl(propimg
								.getString(ApiConstants.URL));
						uploadPropImg.setCreated(propimg
								.getString(ApiConstants.CREATED));
						itemJointPropimgResponse.setPropImg(uploadPropImg);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemJointPropimgResponse;
		
	}
	public ItemImgUploadResponse itemImgUpload(
			ItemImgUploadRequest itemImgUploadRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareItemImgUpload(itemImgUploadRequest);
		return sendItemImgUpload(itemImgUploadRequest, params, sessionId);
	}

	protected Map<String, Object> prepareItemImgUpload(
			ItemImgUploadRequest itemImgUploadRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params
				.put(ApiConstants.ITEMIMG_ID, itemImgUploadRequest
						.getItemImgId());
		params.put(ApiConstants.IID, itemImgUploadRequest.getIid());
		params.put(ApiConstants.POSITION, itemImgUploadRequest.getPosition());
		params.put(ApiConstants.ISMAJOR, itemImgUploadRequest.isMajor());
		return params;
	}

	protected ItemImgUploadResponse sendItemImgUpload(
			ItemImgUploadRequest itemImgUploadRequest,
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = null;
		ItemImgUploadResponse itemImgUploadResponse = null;
		if (itemImgUploadRequest.getImage() != null) {
			response = this.getFetch().fetchWithFile(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.ITEM_IMG_UPLOAD
							.getMethod(), sessionId, params),
					itemImgUploadRequest.getImage());
		} else {
			response = this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.ITEM_IMG_UPLOAD
							.getMethod(), sessionId, params));
		}
		itemImgUploadResponse = new ItemImgUploadResponse(response);
		if (itemImgUploadResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemImgUploadResponse.getBody());
				parseError(itemImgUploadResponse, json);
				if (itemImgUploadResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMIMGS)) {
						JSONArray itemImgs = rsp
								.getJSONArray(ApiConstants.ITEMIMGS);
						JSONObject itemImg = itemImgs.getJSONObject(0);
						ItemImg uploadItemImg = new ItemImg();
						uploadItemImg.setItemimgId(itemImg
								.getString(ApiConstants.ITEMIMG_ID));
						uploadItemImg.setUrl(itemImg
								.getString(ApiConstants.URL));
						uploadItemImg.setCreated(itemImg
								.getString(ApiConstants.CREATED));
						itemImgUploadResponse.setItemImg(uploadItemImg);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemImgUploadResponse;
	}

	public ItemImgDeleteResponse itemImgDelete(
			ItemImgDeleteRequest itemImgDeleteRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareItemImgDelete(itemImgDeleteRequest);
		return sendItemImgDelete(params, sessionId);
	}

	protected Map<String, Object> prepareItemImgDelete(
			ItemImgDeleteRequest itemImgDeleteRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params
				.put(ApiConstants.ITEMIMG_ID, itemImgDeleteRequest
						.getItemImgId());
		params.put(ApiConstants.IID, itemImgDeleteRequest.getIid());
		return params;
	}

	protected ItemImgDeleteResponse sendItemImgDelete(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_IMG_DELETE.getMethod(),
						sessionId, params));
		ItemImgDeleteResponse itemImgDeleteResponse = new ItemImgDeleteResponse(
				response);
		if (itemImgDeleteResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemImgDeleteResponse.getBody());
				parseError(itemImgDeleteResponse, json);
				if (itemImgDeleteResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMIMGS)) {
						JSONArray itemImgs = rsp
								.getJSONArray(ApiConstants.ITEMIMGS);
						JSONObject itemImg = itemImgs.getJSONObject(0);
						ItemImg deleteItemImg = new ItemImg();
						deleteItemImg.setItemimgId(itemImg
								.getString(ApiConstants.ITEMIMG_ID));
						deleteItemImg.setCreated(itemImg
								.getString(ApiConstants.CREATED));
						itemImgDeleteResponse.setItemImg(deleteItemImg);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemImgDeleteResponse;
	}

	public PropimgUploadResponse propImgUpload(
			PropimgUploadRequest propimgUploadRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = preparePropImgUpload(propimgUploadRequest);
		return sendPropImgUpload(propimgUploadRequest, params, sessionId);
	}

	protected Map<String, Object> preparePropImgUpload(
			PropimgUploadRequest propimgUploadRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params
				.put(ApiConstants.PROPIMG_ID, propimgUploadRequest
						.getPropImgId());
		params.put(ApiConstants.IID, propimgUploadRequest.getIid());
		params.put(ApiConstants.PROPERTIES, propimgUploadRequest
				.getProperties());
		params.put(ApiConstants.POSITION, propimgUploadRequest.getPosition());
		return params;
	}

	protected PropimgUploadResponse sendPropImgUpload(
			PropimgUploadRequest propimgUploadRequest,
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = null;
		PropimgUploadResponse propimgUploadResponse = null;
		if (propimgUploadRequest.getImage() != null) {
			response = this.getFetch().fetchWithFile(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.ITEM_PROPIMG_UPLOAD
							.getMethod(), sessionId, params),
					propimgUploadRequest.getImage());
		} else {
			response = this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.ITEM_PROPIMG_UPLOAD
							.getMethod(), sessionId, params));
		}
		propimgUploadResponse = new PropimgUploadResponse(response);
		if (propimgUploadResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(propimgUploadResponse.getBody());
				parseError(propimgUploadResponse, json);
				if (propimgUploadResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.PROPIMGS)) {
						JSONArray propimgs = rsp
								.getJSONArray(ApiConstants.PROPIMGS);
						JSONObject propimg = propimgs.getJSONObject(0);
						PropImg uploadPropImg = new PropImg();
						uploadPropImg.setPropimg_id(propimg
								.getString(ApiConstants.PROPIMG_ID));
						uploadPropImg.setUrl(propimg
								.getString(ApiConstants.URL));
						uploadPropImg.setCreated(propimg
								.getString(ApiConstants.CREATED));
						propimgUploadResponse.setPropImg(uploadPropImg);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return propimgUploadResponse;
	}

	public PropImgDeleteResponse propImgDelete(
			PropImgDeleteRequest propImgDeleteRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = preparePropImgDelete(propImgDeleteRequest);
		return sendPropImgDelete(params, sessionId);
	}

	protected Map<String, Object> preparePropImgDelete(
			PropImgDeleteRequest propImgDeleteRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params
				.put(ApiConstants.PROPIMG_ID, propImgDeleteRequest
						.getPropimgId());
		params.put(ApiConstants.IID, propImgDeleteRequest.getIid());
		return params;
	}

	protected PropImgDeleteResponse sendPropImgDelete(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_PROPIMG_DELETE
						.getMethod(), sessionId, params));
		PropImgDeleteResponse propimgDeleteResponse = new PropImgDeleteResponse(
				response);
		if (propimgDeleteResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(propimgDeleteResponse.getBody());
				parseError(propimgDeleteResponse, json);
				if (propimgDeleteResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.PROPIMGS)) {
						JSONArray propimgs = rsp
								.getJSONArray(ApiConstants.PROPIMGS);
						JSONObject propimg = propimgs.getJSONObject(0);
						PropImg deletePropimg = new PropImg();
						deletePropimg.setPropimg_id(propimg
								.getString(ApiConstants.PROPIMG_ID));
						deletePropimg.setCreated(propimg
								.getString(ApiConstants.CREATED));
						propimgDeleteResponse.setPropImg(deletePropimg);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return propimgDeleteResponse;
	}

	public OrdersGetResponse ordersGet(OrdersGetRequest ordersGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将tradesGetRequest请求中的参数添加到params
		params.put(ApiConstants.IID, ordersGetRequest.getIid());
		params.put(ApiConstants.FIELDS, ordersGetRequest.getFields());
		params.put(ApiConstants.SELLER_NICK, ordersGetRequest.getSellerNick());
		params.put(ApiConstants.PAGE_NO, ordersGetRequest.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, ordersGetRequest.getPageSize());
		params.put(ApiConstants.TYPE, ordersGetRequest.getType());
		
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ORDERS_GET.getMethod(),
						params));
		OrdersGetResponse ordersGetResponse = new OrdersGetResponse(response);
		// 平台访问成功
		if (ordersGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(ordersGetResponse.getBody());
				parseError(ordersGetResponse, json);
				// 淘宝访问成功
				if (ordersGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ORDERS)) {
						JSONArray orders = rsp
								.getJSONArray(ApiConstants.ORDERS);
						ordersGetResponse.setOrders(TaobaoTradeJSONConvert
								.convertJsonToOrderList(orders));
					}
					setTotalResults(rsp, ordersGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return ordersGetResponse;
	}

	public SellerCatsListAddResponse sellerCatsListAdd(
			SellerCatsListAddRequest sellerCatInsertRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareSellerCatsListAdd(sellerCatInsertRequest);
		return sendSellerCatsListAdd(params, sellerCatInsertRequest, sessionId);
	}

	protected Map<String, Object> prepareSellerCatsListAdd(
			SellerCatsListAddRequest sellerCatInsertRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.NAME, sellerCatInsertRequest.getName());
		params.put(ApiConstants.PARENT_CID, sellerCatInsertRequest
				.getParentCid());
		params.put(ApiConstants.PICT_URL, sellerCatInsertRequest.getPictUrl());
		params.put(ApiConstants.SORT_ORDER, sellerCatInsertRequest
				.getSortOrder());
		return params;
	}

	protected SellerCatsListAddResponse sendSellerCatsListAdd(
			Map<String, Object> params,
			SellerCatsListAddRequest sellerCatInsertRequest, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SHOP_SELLERCAT_INSERT
						.getMethod(), sessionId, params));
		SellerCatsListAddResponse sellerCatInsertResponse = new SellerCatsListAddResponse(
				response);
		// 平台访问成功
		if (sellerCatInsertResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(sellerCatInsertResponse.getBody());
				parseError(sellerCatInsertResponse, json);
				// 淘宝访问成功
				if (sellerCatInsertResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SELLER_CATS)) {
						JSONArray catjs = rsp
								.getJSONArray(ApiConstants.SELLER_CATS);
						JSONObject catj = catjs.getJSONObject(0);
						SellerCat cat = new SellerCat();
						try {
							cat.setCreated(DateUtil.strToDate(catj
									.getString(ApiConstants.CREATED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						cat.setCid(catj.getString(ApiConstants.CID));
						sellerCatInsertResponse.setSellerCat(cat);

					}

				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return sellerCatInsertResponse;
	}

	public SellerCatsListUpdateResponse sellerCatsListUpdate(
			SellerCatsListUpdateRequest sellerCatUpdateRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareSellerCatsListUpdate(sellerCatUpdateRequest);
		return sendSellerCatsListUpdate(params, sellerCatUpdateRequest,
				sessionId);
	}

	protected Map<String, Object> prepareSellerCatsListUpdate(
			SellerCatsListUpdateRequest sellerCatUpdateRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.NAME, sellerCatUpdateRequest.getName());
		params.put(ApiConstants.CID, sellerCatUpdateRequest.getCid());
		params.put(ApiConstants.PICT_URL, sellerCatUpdateRequest.getPictUrl());
		params.put(ApiConstants.SORT_ORDER, sellerCatUpdateRequest
				.getSortOrder());
		return params;
	}

	protected SellerCatsListUpdateResponse sendSellerCatsListUpdate(
			Map<String, Object> params,
			SellerCatsListUpdateRequest sellerCatUpdateRequest, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SHOP_SELLERCAT_UPDATE
						.getMethod(), sessionId, params));
		SellerCatsListUpdateResponse sellerCatUpdateResponse = new SellerCatsListUpdateResponse(
				response);
		// 平台访问成功
		if (sellerCatUpdateResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(sellerCatUpdateResponse.getBody());
				parseError(sellerCatUpdateResponse, json);
				// 淘宝访问成功
				if (sellerCatUpdateResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SELLER_CATS)) {
						JSONArray catjs = rsp
								.getJSONArray(ApiConstants.SELLER_CATS);
						JSONObject catj = catjs.getJSONObject(0);
						SellerCat cat = new SellerCat();
						try {
							cat.setModified(DateUtil.strToDate(catj
									.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						cat.setCid(catj.getString(ApiConstants.CID));
						sellerCatUpdateResponse.setSellerCat(cat);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return sellerCatUpdateResponse;
	}

	protected Map<String, Object> prepareShippingAddresses(
			ShippingAddressesGetRequest shippingAddressGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(FIELDS, shippingAddressGetRequest.getFields());
		return params;
	}

	public ShippingAddressesGetResponse shippingAddressesGet(
			ShippingAddressesGetRequest shippingAddressesGetRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareShippingAddresses(shippingAddressesGetRequest);
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SHIPPING_ADDRESSES
						.getMethod(), sessionId, params));
		ShippingAddressesGetResponse shippingAddressesGetResponse = new ShippingAddressesGetResponse(
				response);
		if (shippingAddressesGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(shippingAddressesGetResponse.getBody());
				parseError(shippingAddressesGetResponse, json);
				if (shippingAddressesGetResponse.isSuccess()) {
					// 处理返回结果
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SHIPPING_ADDRESS)) {
						JSONArray shippingAddressList = rsp
								.getJSONArray(ApiConstants.SHIPPING_ADDRESS);
						shippingAddressesGetResponse
								.setShippingAddressList(TaobaoUserJSONConvert
										.convertJsonArrayToShippingAddressList(shippingAddressList));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return shippingAddressesGetResponse;
	}

	public ProductsGetResponse productsGet(ProductsGetRequest productsGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = prepareProductsGet(productsGetRequest);
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.PRODUCTS_GET.getMethod(),
						params));
		ProductsGetResponse productsGetResponse = new ProductsGetResponse(
				response);
		if (productsGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(productsGetResponse.getBody());
				parseError(productsGetResponse, json);
				if (productsGetResponse.isSuccess()) {
					// 处理返回结果
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.PRODUCTS)) {
						JSONArray products = rsp
								.getJSONArray(ProductSearchRequest.PRODUCTS);
						productsGetResponse
								.setProductList(TaobaoProductJSONConvert
										.convertJsonArrayToProductList(products));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return productsGetResponse;
	}

	protected Map<String, Object> prepareProductsGet(
			ProductsGetRequest productsGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, productsGetRequest.getFields());
		params.put(ApiConstants.NICK, productsGetRequest.getNick());
		params.put(ApiConstants.PAGE_NO, productsGetRequest.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, productsGetRequest.getPageSize());
		return params;
	}

	protected Map<String, Object> prepareRefundGet(
			RefundGetRequest refundGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将refundGetRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, refundGetRequest.getFields());
		params.put(ApiConstants.REFUND_ID, refundGetRequest.getRefundId());
		params.put(ApiConstants.BIZ_ORDER_ID, refundGetRequest.getBizOrderId());
		return params;
	}

	protected RefundGetResponse sendRefundGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.REFUND_GET.getMethod(),
						sessionId, params));
		RefundGetResponse refundGetResponse = new RefundGetResponse(response);
		// 平台成功访问
		if (refundGetResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(refundGetResponse.getBody());
				parseError(refundGetResponse, json);
				// 访问淘宝成功
				if (refundGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.REFUNDS)) {
						JSONArray refunds = rsp
								.getJSONArray(ApiConstants.REFUNDS);
						JSONObject refund = refunds.getJSONObject(0);
						refundGetResponse.setRefund(TaobaoRefundJSONConvert
								.convertJsonToRefund(refund));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return refundGetResponse;
	}

	public RefundGetResponse refundGet(RefundGetRequest refundGetRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareRefundGet(refundGetRequest);
		return sendRefundGet(params, sessionId);
	}

	public RefundMessagesGetResponse refundMessagesGet(
			RefundMessagesGetRequest refundMessagesGetRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareRefundMessagesGet(refundMessagesGetRequest);
		return sendRefundMessagesGet(params, sessionId);
	}

	protected Map<String, Object> prepareRefundMessagesGet(
			RefundMessagesGetRequest refundMessagesGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将refundGetRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, refundMessagesGetRequest.getFields());
		params.put(ApiConstants.REFUND_ID, refundMessagesGetRequest
				.getRefundId());
		params.put(ApiConstants.PAGE_NO, refundMessagesGetRequest.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, refundMessagesGetRequest
				.getPageSize());
		return params;
	}

	protected RefundMessagesGetResponse sendRefundMessagesGet(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.REFUND_MESSAGES_GET
						.getMethod(), sessionId, params));
		RefundMessagesGetResponse refundMessagesGetResponse = new RefundMessagesGetResponse(
				response);
		// 平台访问成功
		if (refundMessagesGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(refundMessagesGetResponse.getBody());
				parseError(refundMessagesGetResponse, json);
				// 淘宝访问成功
				if (refundMessagesGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.REFUND_MESSAGES)) {
						JSONArray refundMessages = rsp
								.getJSONArray(ApiConstants.REFUND_MESSAGES);
						refundMessagesGetResponse
								.setRefundMessageList(TaobaoRefundMessageJSONConvert
										.convertJsonArrayToRefundMessageList(refundMessages));
					}
					setTotalResults(rsp, refundMessagesGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return refundMessagesGetResponse;
	}

	public RefundMessageAddResponse refundMessageAdd(
			RefundMessageAddRequest refundMessageAddRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareRefundMessageAdd(refundMessageAddRequest);
		return sendRefundMessageAdd(params, refundMessageAddRequest, sessionId);
	}

	protected Map<String, Object> prepareRefundMessageAdd(
			RefundMessageAddRequest refundMessageAddRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.CONTENT, refundMessageAddRequest.getContent());
		params.put(ApiConstants.OWNER_NICK, refundMessageAddRequest
				.getOwnerNick());
		params.put(ApiConstants.REFUND_ID, refundMessageAddRequest
				.getRefundId());
		return params;
	}

	protected RefundMessageAddResponse sendRefundMessageAdd(
			Map<String, Object> params,
			RefundMessageAddRequest refundMessageAddRequest, String sessionId)
			throws TaobaoApiException {
		RefundMessageAddResponse refundMessageAddResponse = getRefundMessageAddResponse(
				refundMessageAddRequest, sessionId, params);
		// 平台成功访问
		if (refundMessageAddResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(refundMessageAddResponse
						.getBody());
				parseError(refundMessageAddResponse, json);
				// 访问淘宝成功
				if (refundMessageAddResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.REFUND_MESSAGES)) {
						JSONArray refundMessages = rsp
								.getJSONArray(ApiConstants.REFUND_MESSAGES);
						JSONObject refundMessage = refundMessages
								.getJSONObject(0);
						RefundMessage addedRefundMessage = new RefundMessage();
						try {
							addedRefundMessage.setCreated(DateUtil
									.strToDate(refundMessage
											.getString(ApiConstants.CREATED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						addedRefundMessage.setMessageId(refundMessage
								.getString(ApiConstants.MESSAGE_ID));
						refundMessageAddResponse
								.setRefundMessage(addedRefundMessage);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return refundMessageAddResponse;
	}

	private RefundMessageAddResponse getRefundMessageAddResponse(
			RefundMessageAddRequest refundMessageAddRequest, String sessionId,
			Map<String, Object> paramsMap) throws TaobaoApiException {
		TaobaoResponse rsp = null;
		// 根据添加留言凭证是否有图片选择不同的请求方法
		if (refundMessageAddRequest.getImage() != null) {
			rsp = this.getFetch().fetchWithFile(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.REFUND_MESSAGE_ADD
							.getMethod(), sessionId, paramsMap),
					refundMessageAddRequest.getImage());
		} else {
			rsp = this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.REFUND_MESSAGE_ADD
							.getMethod(), sessionId, paramsMap));
		}
		return new RefundMessageAddResponse(rsp);
	}

	protected Map<String, Object> prepareRefundsApplayGet(
			RefundsApplyGetRequest refundsApplyGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将tradesRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, refundsApplyGetRequest.getFields());
		params.put(ApiConstants.PAGE_NO, refundsApplyGetRequest.getPageNo());
		params
				.put(ApiConstants.PAGE_SIZE, refundsApplyGetRequest
						.getPageSize());
		params.put(ApiConstants.STATUS, refundsApplyGetRequest.getStatus());
		params.put(ApiConstants.TYPE, refundsApplyGetRequest.getType());
		params.put(ApiConstants.SELLER_NICK, refundsApplyGetRequest
				.getSellerNick());
		return params;
	}

	protected RefundsApplyGetResponse sendRefundsApplayGet(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.REFUNDS_APPLY_GET
						.getMethod(), sessionId, params));
		RefundsApplyGetResponse refundsApplyGetResponse = new RefundsApplyGetResponse(
				response);
		// 平台访问成功
		if (refundsApplyGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(refundsApplyGetResponse.getBody());
				parseError(refundsApplyGetResponse, json);
				// 淘宝访问成功
				if (refundsApplyGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.REFUNDS)) {
						JSONArray refunds = rsp
								.getJSONArray(ApiConstants.REFUNDS);
						refundsApplyGetResponse
								.setRefundList(TaobaoRefundJSONConvert
										.convertJsonArrayToRefundList(refunds));
					}
					setTotalResults(rsp, refundsApplyGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return refundsApplyGetResponse;
	}

	public RefundsApplyGetResponse refundsApplyGet(
			RefundsApplyGetRequest refundsApplyGetRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareRefundsApplayGet(refundsApplyGetRequest);
		return sendRefundsApplayGet(params, sessionId);
	}

	protected Map<String, Object> prepareRefundsRecieveGet(
			RefundsRecieveGetRequest refundsRecieveGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		// 先将refundsRecieveGetRequest请求中的参数添加到params
		params.put(ApiConstants.FIELDS, refundsRecieveGetRequest.getFields());
		params.put(ApiConstants.PAGE_NO, refundsRecieveGetRequest.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, refundsRecieveGetRequest.getPageSize());
		params.put(ApiConstants.STATUS, refundsRecieveGetRequest.getStatus());
		params.put(ApiConstants.TYPE, refundsRecieveGetRequest.getType());
		params.put(ApiConstants.BUYER_NICK, refundsRecieveGetRequest.getBuyerNick());
		params.put(ApiConstants.START_MODIFIED, refundsRecieveGetRequest.getStartModified());
		params.put(ApiConstants.END_MODIFIED, refundsRecieveGetRequest.getEndModified());
		return params;
	}

	protected RefundsRecieveGetResponse sendRefundsRecieveGet(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.REFUNDS_RECIEVE_GET
						.getMethod(), sessionId, params));
		RefundsRecieveGetResponse refundsRecieveGetResponse = new RefundsRecieveGetResponse(
				response);
		// 平台访问成功
		if (refundsRecieveGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(refundsRecieveGetResponse.getBody());
				parseError(refundsRecieveGetResponse, json);
				// 淘宝访问成功
				if (refundsRecieveGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.REFUNDS)) {
						JSONArray refunds = rsp
								.getJSONArray(ApiConstants.REFUNDS);
						refundsRecieveGetResponse
								.setRefundList(TaobaoRefundJSONConvert
										.convertJsonArrayToRefundList(refunds));
					}
					setTotalResults(rsp, refundsRecieveGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return refundsRecieveGetResponse;
	}

	public RefundsRecieveGetResponse refundsRecieveGet(
			RefundsRecieveGetRequest refundsRecieveGetRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareRefundsRecieveGet(refundsRecieveGetRequest);
		return sendRefundsRecieveGet(params, sessionId);
	}

	public SuitesGetResponse suitesGet(SuiteGetRequest suiteGetRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareSuitesGet(suiteGetRequest);
		return sendSuitesGet(params, sessionId);
	}

	protected Map<String, Object> prepareSuitesGet(
			SuiteGetRequest suiteGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.SERVICE_CODE, suiteGetRequest.getServiceCode());
		return params;
	}

	protected SuitesGetResponse sendSuitesGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SUITES_GET.getMethod(),
						sessionId, params));
		SuitesGetResponse suitesGetResponse = new SuitesGetResponse(response);

		// 平台成功访问
		if (suitesGetResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(suitesGetResponse.getBody());
				parseError(suitesGetResponse, json);
				// 访问淘宝成功
				if (suitesGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SUITES)) {
						JSONArray suites = rsp
								.getJSONArray(ApiConstants.SUITES);
						suitesGetResponse.setSuites(TaobaoSuiteJSONConvert
								.convertJsonArrayToSuiteList(suites));
					}
					setTotalResults(rsp, suitesGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return suitesGetResponse;
	}
	
	public VasSuitesgGetResponse vasSuitesGet(VasSuitesgGetRequest suitesgGetRequest, String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareVasSuitesGet(suitesgGetRequest);
		return sendVasSuitesGet(params, sessionId);
	}
	
	protected Map<String, Object> prepareVasSuitesGet(VasSuitesgGetRequest request) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.SERVICE_CODE, request.getServiceCode());
		return params;
	}
	
	protected VasSuitesgGetResponse sendVasSuitesGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),getTemplateRequest(TaobaoApiMethod.VAS_SUITES_GET.getMethod(),sessionId, params));
		VasSuitesgGetResponse suitesGetResponse = new VasSuitesgGetResponse(response);
		// 平台成功访问
		if (suitesGetResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(suitesGetResponse.getBody());
				parseError(suitesGetResponse, json);
				// 访问淘宝成功
				if (suitesGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SUITES)) {
						JSONArray suites = rsp
								.getJSONArray(ApiConstants.SUITES);
						suitesGetResponse.setSuites(TaobaoSuiteJSONConvert
								.convertJsonArrayToSuiteList(suites));
					}
					setTotalResults(rsp, suitesGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return suitesGetResponse;
	}
	
	public TradeCloseResponse tradeClose(TradeCloseRequest tradeCloseRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareTradeClose(tradeCloseRequest);
		return sendTradeClose(params, sessionId);
	}

	protected TradeCloseResponse sendTradeClose(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TRADE_CLOSE.getMethod(),
						sessionId, params));
		TradeCloseResponse tradeCloseResponse = new TradeCloseResponse(response);

		// 平台成功访问
		if (tradeCloseResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(tradeCloseResponse.getBody());
				parseError(tradeCloseResponse, json);
				// 访问淘宝成功
				if (tradeCloseResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TRADES)) {
						JSONArray trades = rsp
								.getJSONArray(ApiConstants.TRADES);
						JSONObject trade = trades.getJSONObject(0);
						Trade closeTrade = new Trade();
						try {
							closeTrade.setModified(DateUtil.strToDate(trade
									.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						closeTrade.setTid(trade.getString(ApiConstants.TID));
						tradeCloseResponse.setTrade(closeTrade);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return tradeCloseResponse;
	}

	protected Map<String, Object> prepareTradeClose(
			TradeCloseRequest tradeCloseRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.TID, tradeCloseRequest.getTid());
		params.put(ApiConstants.CLOSE_REASON, tradeCloseRequest
				.getCloseReason());
		return params;
	}

	protected Map<String, Object> prepareProductAdd(
			ProductAddRequest productAddRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ProductAddRequest.CID, productAddRequest.getCid());
		params.put(ProductAddRequest.BINDS, productAddRequest.getBinds());
		params.put(ProductAddRequest.DESC, productAddRequest.getDesc());
		params.put(ProductAddRequest.NAME, productAddRequest.getName());
		params.put(ProductAddRequest.PRICE, productAddRequest.getPrice());
		params.put(ProductAddRequest.PROPS, productAddRequest.getProps());
		params.put(ProductAddRequest.SALEPROPS, productAddRequest
				.getSaleProps());
		params.put(ProductAddRequest.OUTER_ID, productAddRequest.getOuterId());
		params.put(ProductAddRequest.CUSETOMER_PROPS, productAddRequest
				.getCustomerProps());
		return params;
	}

	private ProductAddResponse getProductAddResponse(
			ProductAddRequest productAddRequest, String sessionId,
			Map<String, Object> paramsMap) throws TaobaoApiException {
		TaobaoResponse rsp = null;
		// 根据添加商品是否有图片选择不同的请求方法
		if (productAddRequest.getImage() != null) {
			rsp = this.getFetch()
					.fetchWithFile(
							this.getServiceUrl(),
							getTemplateRequest(TaobaoApiMethod.PRODUCT_ADD
									.getMethod(), sessionId, paramsMap),
							productAddRequest.getImage());
		} else {
			rsp = this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.PRODUCT_ADD.getMethod(),
							sessionId, paramsMap));
		}
		return new ProductAddResponse(rsp);
	}

	protected ProductAddResponse sendProductAdd(Map<String, Object> params,
			ProductAddRequest productAddRequest, String sessionId)
			throws TaobaoApiException {
		ProductAddResponse productAddResponse = getProductAddResponse(
				productAddRequest, sessionId, params);
		// 平台成功访问
		if (productAddResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(productAddResponse.getBody());
				parseError(productAddResponse, json);
				// 访问淘宝成功
				if (productAddResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ProductAddRequest.PRODUCT)) {
						JSONArray products = rsp
								.getJSONArray(ProductAddRequest.PRODUCT);
						JSONObject product = products.getJSONObject(0);
						Product addedProduct = new Product();
						try {
							addedProduct.setCreated(DateUtil.strToDate(product
									.getString(ApiConstants.CREATED)));
						} catch (ParseException e) {
							e.printStackTrace();
						}
						addedProduct.setProductId(product
								.getString(ApiConstants.PRODUCT_ID));
						productAddResponse.setProduct(addedProduct);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return productAddResponse;
	}

	public ProductAddResponse productAdd(ProductAddRequest productAddRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareProductAdd(productAddRequest);
		return sendProductAdd(params, productAddRequest, sessionId);
	}

	protected Map<String, Object> prepareProductUpdate(
			ProductUpdateRequest productUpdateRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ProductUpdateRequest.PRODUCTID, productUpdateRequest
				.getProductId());
		params.put(ProductUpdateRequest.BINDS, productUpdateRequest.getBinds());
		params.put(ProductUpdateRequest.DESC, productUpdateRequest.getDesc());
		params.put(ProductUpdateRequest.NAME, productUpdateRequest.getName());
		params.put(ProductUpdateRequest.PRICE, productUpdateRequest.getPrice());
		params.put(ProductUpdateRequest.SALEPROPS, productUpdateRequest
				.getSaleProps());
		// params.put(ProductUpdateRequest.TSC, productUpdateRequest.getTsc());
		params.put(ProductUpdateRequest.OUTER_ID, productUpdateRequest
				.getOuterId());
		params.put(ProductAddRequest.CUSETOMER_PROPS, productUpdateRequest
				.getCustomerProps());
		return params;
	}

	protected ProductUpdateResponse sendProductUpdate(
			Map<String, Object> params,
			ProductUpdateRequest productUpdateRequest, String sessionId)
			throws TaobaoApiException {
		ProductUpdateResponse productUpdateResponse = getProductUpdateResponse(
				productUpdateRequest, sessionId, params);
		// 平台成功访问
		if (productUpdateResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(productUpdateResponse
						.getBody());
				parseError(productUpdateResponse, json);
				// 访问淘宝成功
				if (productUpdateResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ProductAddRequest.PRODUCT)) {
						JSONArray products = rsp
								.getJSONArray(ProductAddRequest.PRODUCT);
						JSONObject product = products.getJSONObject(0);
						Product addedProduct = new Product();
						try {
							addedProduct.setModified(DateUtil.strToDate(product
									.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							e.printStackTrace();
						}
						addedProduct.setProductId(product
								.getString(ApiConstants.PRODUCT_ID));
						productUpdateResponse.setProduct(addedProduct);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return productUpdateResponse;
	}

	/**
	 * 获得更新product API的相应response
	 * 
	 * @param req
	 *            更新商品的请求
	 * @param sessionId
	 *            请求中包含的session id
	 * @param params
	 *            求参数
	 * @return ProductUpdateResponse
	 * @throws TaobaoApiException
	 */
	private ProductUpdateResponse getProductUpdateResponse(
			ProductUpdateRequest req, String sessionId,
			Map<String, Object> params) throws TaobaoApiException {
		TaobaoResponse rsp = null;
		// 根据添加SPU是否有图片选择不同的请求方法
		if (req.getImage() != null) {
			rsp = this.getFetch().fetchWithFile(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.PRODUCT_UPDATE
							.getMethod(), sessionId, params), req.getImage());
		} else {
			rsp = this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.PRODUCT_UPDATE
							.getMethod(), sessionId, params));
		}
		return new ProductUpdateResponse(rsp);
	}

	public ProductUpdateResponse productUpdate(
			ProductUpdateRequest productUpdateRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareProductUpdate(productUpdateRequest);
		return sendProductUpdate(params, productUpdateRequest, sessionId);
	}

	public TaobaokeItemsGetResponse taobaokeItemsGet(
			TaobaokeItemsGetRequest request) throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, request.getField());
		params.put(ApiConstants.KEYWORD, request.getKeyword());
		params.put(ApiConstants.CID, request.getCid());
		params.put(ApiConstants.PID, request.getPid());
		params.put(ApiConstants.START_PRICE, request.getStartPrice());
		params.put(ApiConstants.END_PRICE, request.getEndPrice());
		params.put(ApiConstants.SEND_TYPE, request.getAutoSend());
		params.put(ApiConstants.AREA, request.getArea());
		params.put(ApiConstants.START_CREDIT, request.getStartCredit());
		params.put(ApiConstants.END_CREDIT, request.getEndCredit());
		params.put(ApiConstants.SORT, request.getSort());
		params.put(ApiConstants.GUARANTEE, request.getIsGuarantee());
		params.put(ApiConstants.PAGE_NO, request.getPageNo());
		params.put(ApiConstants.PAGE_SIZE, request.getPageSize());
		params.put(ApiConstants.START_COMMISSION, request.getStartCommission());
		params.put(ApiConstants.END_COMMISSION, request.getEndCommission());
		params.put(ApiConstants.START_COMMISSION_RATE, request
				.getStartCommissionRate());
		params.put(ApiConstants.END_COMMISSION_RATE, request
				.getEndCommissionRate());
		params.put(ApiConstants.START_COMMISSION_NUM, request
				.getStartCommissionNum());
		params.put(ApiConstants.END_COMMISSION_NUM, request
				.getEndCommissionNum());
		TaobaoResponse response = getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TAOBAO_TAOKE_ITEMS_GET
						.getMethod(), params));
		TaobaokeItemsGetResponse taokeItemsGetResponse = new TaobaokeItemsGetResponse(
				response);
		if (taokeItemsGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(taokeItemsGetResponse.getBody());
				parseError(taokeItemsGetResponse, json);
				// 访问淘宝成功
				if (taokeItemsGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TAOBAO_TAOKE_ITEMS)) {
						JSONArray items = rsp
								.getJSONArray(ApiConstants.TAOBAO_TAOKE_ITEMS);
						taokeItemsGetResponse.setItems(TaobaoItemJSONConvert
								.convertJsonArrayToTaobaokeItem(items));
					}
					setTotalResults(rsp, taokeItemsGetResponse);
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return taokeItemsGetResponse;
	}

	public TaobaokeItemsConvertResponse taobaokeItemsConvert(
			TaobaokeItemsConvertRequest itemsConvertRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, itemsConvertRequest.getField());
		params.put(ApiConstants.IIDS, itemsConvertRequest.getIids());
		params.put(ApiConstants.NICK, itemsConvertRequest.getNick());
		params.put(ApiConstants.OUTER_CODE, itemsConvertRequest.getOuterCode());
		TaobaoResponse response = getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(
						TaobaoApiMethod.TAOBAO_TAOBAOKE_ITEMS_CONVERT
								.getMethod(), params));
		TaobaokeItemsConvertResponse convertResponse = new TaobaokeItemsConvertResponse(
				response);
		if (convertResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(convertResponse.getBody());
				parseError(convertResponse, json);
				// 访问淘宝成功
				if (convertResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TAOBAO_TAOKE_ITEMS)) {
						JSONArray items = rsp
								.getJSONArray(ApiConstants.TAOBAO_TAOKE_ITEMS);
						convertResponse.setItems(TaobaoItemJSONConvert
								.convertJsonArrayToTaobaokeItem(items));
						convertResponse.setTotalResults(items.length());
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return convertResponse;
	}

	public TaobaokeShopsConvertResponse taobaokeShopsConvert(
			TaobaokeShopsConvertRequest shopsConvertRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, shopsConvertRequest.getField());
		params.put(ApiConstants.SIDS, shopsConvertRequest.getSids());
		params.put(ApiConstants.NICK, shopsConvertRequest.getNick());
		params.put(ApiConstants.OUTER_CODE, shopsConvertRequest.getOuterCode());
		TaobaoResponse response = getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(
						TaobaoApiMethod.TAOBAO_TAOBAOKE_SHOPS_CONVERT
								.getMethod(), params));
		TaobaokeShopsConvertResponse convertResponse = new TaobaokeShopsConvertResponse(
				response);
		if (convertResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(convertResponse.getBody());
				parseError(convertResponse, json);
				// 访问淘宝成功
				if (convertResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TAOBAO_TAOBAOKE_SHOPS)) {
						JSONArray items = rsp
								.getJSONArray(ApiConstants.TAOBAO_TAOBAOKE_SHOPS);
						convertResponse.setShops(TaobaoItemJSONConvert
								.convertJsonArrayToTaobaokeShop(items));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return convertResponse;
	}

	public TaobaokeListUrlGetResponse taobaokeListUrlGet(
			TaobaokeListUrlGetRequest listUrlGetRequest)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.Q, listUrlGetRequest.getQ());
		params.put(ApiConstants.NICK, listUrlGetRequest.getNick());
		params.put(ApiConstants.OUTER_CODE, listUrlGetRequest.getOuterCode());
		TaobaoResponse response = getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TAOBAO_TAOBAOKE_LISTURL_GET
						.getMethod(), params));
		TaobaokeListUrlGetResponse listUrlGetResponse = new TaobaokeListUrlGetResponse(
				response);
		if (listUrlGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(listUrlGetResponse.getBody());
				parseError(listUrlGetResponse, json);
				// 访问淘宝成功
				if (listUrlGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TAOBAO_TAOKE_ITEMS)) {
						JSONArray urls = rsp
								.getJSONArray(ApiConstants.TAOBAO_TAOKE_ITEMS);
						JSONObject url = urls.getJSONObject(0);
						listUrlGetResponse.setKeywordClickUrl(url
								.getString("list_url_by_q"));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return listUrlGetResponse;
	}

	protected TradeGetResponse sendTradeFullInfoGet(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TRADE_FULLINFO_GET
						.getMethod(), sessionId, params));
		TradeGetResponse tradeGetResponse = new TradeGetResponse(response);
		// 平台成功访问
		if (tradeGetResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(tradeGetResponse.getBody());
				parseError(tradeGetResponse, json);
				// 访问淘宝成功
				if (tradeGetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TRADES)) {
						JSONArray trades = rsp
								.getJSONArray(ApiConstants.TRADES);
						JSONObject trade = trades.getJSONObject(0);
						tradeGetResponse.setTrade(TaobaoTradeJSONConvert
								.convertJsonToTrade(trade));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return tradeGetResponse;
	}

	public TradeGetResponse tradeFullInfoGet(TradeGetRequest tradeGetRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareTradeGet(tradeGetRequest);
		return sendTradeFullInfoGet(params, sessionId);
	}

	protected Map<String, Object> prepareTradeMemoAdd(
			TradeMemoAddRequest tradeMemoAddRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.MEMO, tradeMemoAddRequest.getMemo());
		params.put(ApiConstants.TID, tradeMemoAddRequest.getTid());
		return params;
	}

	protected TradeMemoAddResponse sendTradeMemoAdd(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TRADE_MEMO_ADD.getMethod(),
						sessionId, params));
		TradeMemoAddResponse tradeMemoAddResponse = new TradeMemoAddResponse(
				response);
		// 平台成功访问
		if (tradeMemoAddResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(tradeMemoAddResponse.getBody());
				parseError(tradeMemoAddResponse, json);
				// 访问淘宝成功
				if (tradeMemoAddResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TRADES)) {
						JSONArray trades = rsp
								.getJSONArray(ApiConstants.TRADES);
						JSONObject trade = trades.getJSONObject(0);
						Trade newTradeMemo = new Trade();
						if (trade.has(ApiConstants.CREATED)) {
							try {
								newTradeMemo
										.setCreated(DateUtil
												.strToDate(trade
														.getString(ApiConstants.CREATED)));
							} catch (ParseException e) {
								throw new TaobaoApiException();
							}
						}
						if (trade.has(ApiConstants.TID)) {
							newTradeMemo.setTid(trade
									.getString(ApiConstants.TID));
						}
						tradeMemoAddResponse.setTrade(newTradeMemo);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return tradeMemoAddResponse;
	}

	public TradeMemoAddResponse tradeMemoAdd(
			TradeMemoAddRequest tradeMemoAddRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareTradeMemoAdd(tradeMemoAddRequest);
		return sendTradeMemoAdd(params, sessionId);
	}

	protected Map<String, Object> prepareTradeMemoUpdate(
			TradeMemoUpdateRequest tradeMemoUpdateRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.MEMO, tradeMemoUpdateRequest.getMemo());
		params.put(ApiConstants.TID, tradeMemoUpdateRequest.getTid());
		return params;
	}

	protected TradeMemoUpdateResponse sendTradeMemoUpdate(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TRADE_MEMO_UPDATE
						.getMethod(), sessionId, params));
		TradeMemoUpdateResponse tradeMemoUpdateResponse = new TradeMemoUpdateResponse(
				response);
		// 平台成功访问
		if (tradeMemoUpdateResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(tradeMemoUpdateResponse
						.getBody());
				parseError(tradeMemoUpdateResponse, json);
				// 访问淘宝成功
				if (tradeMemoUpdateResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.TRADES)) {
						JSONArray trades = rsp
								.getJSONArray(ApiConstants.TRADES);
						JSONObject trade = trades.getJSONObject(0);
						Trade newTradeMemo = new Trade();
						if (trade.has(ApiConstants.MODIFIED)) {
							try {
								newTradeMemo
										.setModified(DateUtil
												.strToDate(trade
														.getString(ApiConstants.MODIFIED)));
							} catch (ParseException e) {
								throw new TaobaoApiException();
							}
						}
						if (trade.has(ApiConstants.TID)) {
							newTradeMemo.setTid(trade
									.getString(ApiConstants.TID));
						}
						tradeMemoUpdateResponse.setTrade(newTradeMemo);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return tradeMemoUpdateResponse;
	}

	public TradeMemoUpdateResponse tradeMemoUpdate(
			TradeMemoUpdateRequest tradeMemoUpdateRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareTradeMemoUpdate(tradeMemoUpdateRequest);
		return sendTradeMemoUpdate(params, sessionId);
	}

	public FullitemsGetResponse fullitems(FullitemsGetRequest req,
			String sessionId) throws TaobaoApiException {
		return new FullitemsGetResponse(this.itemsOutGet(req, sessionId));
	}

	public ItemsOutGetResponse itemsOutGet(ItemsOutGetRequest req, String sessionId)
			throws TaobaoApiException {
		return new ItemsOutGetResponse(this.itemsCustomGet(req, sessionId));
	}

	public ItemsCustomGetResponse itemsCustomGet(ItemsCustomGetRequest req, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareItemsCustomGet(req);
		return getCustomItems(params, sessionId);
	}

	protected ItemsCustomGetResponse getCustomItems(Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
						getTemplateRequest(TaobaoApiMethod.ITEMS_CUSTOM_GET.getMethod(), sessionId, params));
		ItemsCustomGetResponse itemsOutGetResponse = new ItemsCustomGetResponse(response);
		if (itemsOutGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemsOutGetResponse.getBody());
				parseError(itemsOutGetResponse, json);
				if (itemsOutGetResponse.isSuccess()) {
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						itemsOutGetResponse.setItem(TaobaoItemJSONConvert
								.convertJsonArrayToItemList(items));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemsOutGetResponse;
	}

	protected Map<String, Object> prepareItemsCustomGet(ItemsCustomGetRequest req) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.OUTER_ID, req.getOuterId());
		params.put(ApiConstants.FIELDS, req.getFields());
		return params;
	}

	public SellerAuthorizeGetResponse sellerAuthorizeGet(SellerAuthorizeGetRequest req,
			String sessionId) throws TaobaoApiException {
		return new SellerAuthorizeGetResponse(itemCatsAuthorizeGet(req, sessionId));
	}

	public ItemCatsAuthorizeGetResponse itemCatsAuthorizeGet(ItemCatsAuthorizeGetRequest req,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareItemCatsAuthorizeGet(req);
		return getAuthorizeItemCats(params, sessionId);
	}

	protected Map<String, Object> prepareItemCatsAuthorizeGet(ItemCatsAuthorizeGetRequest req) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.FIELDS, req.getFields());
		return params;
	}

	protected ItemCatsAuthorizeGetResponse getAuthorizeItemCats(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse rsp = getFetch().fetch(getServiceUrl(),getTemplateRequest(
				TaobaoApiMethod.ITEMCATS_AUTHORIZE_GET.getMethod(), sessionId, params));

		ItemCatsAuthorizeGetResponse result = new ItemCatsAuthorizeGetResponse(rsp);
		SellerAuthorize sellerAuthorize = null;

		// 访问淘宝成功
		if (result.isSuccess()) {
			try {
				JSONObject jsonRoot = new JSONObject(result.getBody());
				parseError(result, jsonRoot); // 容错
				if (result.isSuccess()) { // 容错之后是否还成功
					jsonRoot = jsonRoot.getJSONObject(ApiConstants.RSP);

					// 授权信息
					if (jsonRoot.has(ApiConstants.SELLER_AUTHORIZE)) {
						JSONObject auth = jsonRoot.getJSONArray(ApiConstants.SELLER_AUTHORIZE)
								.getJSONObject(0);
						sellerAuthorize = new SellerAuthorize();

						if (auth.has(ApiConstants.ITEM_CATS)) {// 类目
							JSONArray itemCats = auth.getJSONArray(ApiConstants.ITEM_CATS);
							sellerAuthorize.setItemCats(TaobaoItemJSONConvert
									.convertJsonArrayToItemCatList(itemCats));
						}

						if (auth.has(ApiConstants.BRANDS)) {// 品牌
							JSONArray brands = auth.getJSONArray(ApiConstants.BRANDS);
							sellerAuthorize.setBrands(TaobaoBrandJSONConvert
									.convertJsonArray2BrandList(brands));
						}

						setTotalResults(auth, result);
					}
				}
			} catch (Exception e) {
				throw new TaobaoApiException(e);
			}
		}

		result.setAuthorizes(sellerAuthorize);
		return result;
	}

	public ProductImgUploadResponse productImgUpload(
			ProductImgUploadRequest productImgUploadRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ProductImgUploadRequest.PICID, productImgUploadRequest
				.getPicId());
		params.put(ProductImgUploadRequest.PRODUCTID, productImgUploadRequest
				.getProductId());
		params.put(ProductImgUploadRequest.MAJOR, productImgUploadRequest
				.getMajor());
		params.put(ProductImgUploadRequest.POSITION, productImgUploadRequest
				.getPosition());
		ProductImgUploadResponse productImgUploadResponse = getProductImgUploadResponse(
				productImgUploadRequest, sessionId, params);
		// 平台成功访问
		if (productImgUploadResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(productImgUploadResponse
						.getBody());
				parseError(productImgUploadResponse, json);
				// 访问淘宝成功
				if (productImgUploadResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ProductImgUploadRequest.PRODUCTIMG)) {
						JSONArray products = rsp
								.getJSONArray(ProductImgUploadRequest.PRODUCTIMG);
						JSONObject product = products.getJSONObject(0);
						ProductImg addedProduct = new ProductImg();
						try {
							addedProduct.setCreated(DateUtil.strToDate(product
									.getString(ApiConstants.CREATED)));
							addedProduct.setModified(DateUtil.strToDate(product
									.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						addedProduct.setPicId(product
								.getString(ApiConstants.PICID));
						addedProduct
								.setUrl(product.getString(ApiConstants.URL));
						productImgUploadResponse.setProductImg(addedProduct);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return productImgUploadResponse;
	}

	private ProductImgUploadResponse getProductImgUploadResponse(
			ProductImgUploadRequest productImgUploadRequest, String sessionId,
			Map<String, Object> paramsMap) throws TaobaoApiException {
		TaobaoResponse rsp = null;
		// 根据添加商品是否有图片选择不同的请求方法
		if (productImgUploadRequest.getImage() != null) {
			rsp = this.getFetch().fetchWithFile(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.PRODUCT_IMG_UPLOAD
							.getMethod(), sessionId, paramsMap),
					productImgUploadRequest.getImage());
		} else {
			rsp = this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.PRODUCT_IMG_UPLOAD
							.getMethod(), sessionId, paramsMap));
		}
		return new ProductImgUploadResponse(rsp);
	}

	public ProductPropImgUploadResponse productPropImgUpload(
			ProductPropImgUploadRequest productPropImgUploadRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ProductPropImgUploadRequest.PICID,
				productPropImgUploadRequest.getPicId());
		params.put(ProductPropImgUploadRequest.PRODUCTID,
				productPropImgUploadRequest.getProductId());
		params.put(ProductPropImgUploadRequest.PROPS,
				productPropImgUploadRequest.getProps());
		params.put(ProductPropImgUploadRequest.POSITION,
				productPropImgUploadRequest.getPosition());
		ProductPropImgUploadResponse productPropImgUploadResponse = getProductPropImgUploadResponse(
				productPropImgUploadRequest, sessionId, params);
		// 平台成功访问
		if (productPropImgUploadResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(productPropImgUploadResponse
						.getBody());
				parseError(productPropImgUploadResponse, json);
				// 访问淘宝成功
				if (productPropImgUploadResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ProductPropImgUploadRequest.PRODUCTPROPIMG)) {
						JSONArray products = rsp
								.getJSONArray(ProductPropImgUploadRequest.PRODUCTPROPIMG);
						JSONObject product = products.getJSONObject(0);
						ProductPropImg addedProduct = new ProductPropImg();
						try {
							addedProduct.setCreated(DateUtil.strToDate(product
									.getString(ApiConstants.CREATED)));
							addedProduct.setModified(DateUtil.strToDate(product
									.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
						addedProduct.setPicId(product
								.getString(ApiConstants.PICID));
						addedProduct
								.setUrl(product.getString(ApiConstants.URL));
						productPropImgUploadResponse
								.setProductPropImg(addedProduct);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return productPropImgUploadResponse;
	}

	private ProductPropImgUploadResponse getProductPropImgUploadResponse(
			ProductPropImgUploadRequest productPropImgUploadRequest,
			String sessionId, Map<String, Object> paramsMap)
			throws TaobaoApiException {
		TaobaoResponse rsp = null;
		// 根据添加商品是否有图片选择不同的请求方法
		if (productPropImgUploadRequest.getImage() != null) {
			rsp = this.getFetch().fetchWithFile(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.PRODUCT_PROPIMG_UPLOAD
							.getMethod(), sessionId, paramsMap),
					productPropImgUploadRequest.getImage());
		} else {
			rsp = this.getFetch().fetch(
					this.getServiceUrl(),
					getTemplateRequest(TaobaoApiMethod.PRODUCT_PROPIMG_UPLOAD
							.getMethod(), sessionId, paramsMap));
		}
		return new ProductPropImgUploadResponse(rsp);
	}

	public ProductImgDeleteResponse productImgDelete(
			ProductImgDeleteRequest productImgDeleteRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ProductImgDeleteRequest.PICID, productImgDeleteRequest
				.getPicId());
		params.put(ProductImgDeleteRequest.PRODUCTID, productImgDeleteRequest
				.getProductId());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.PRODUCT_IMG_DELETE
						.getMethod(), sessionId, params));
		ProductImgDeleteResponse productImgDeleteResponse = new

		ProductImgDeleteResponse(response);
		// 平台访问成功
		if (productImgDeleteResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(productImgDeleteResponse.getBody());
				parseError(productImgDeleteResponse, json);
				// 访问淘宝成功
				if (productImgDeleteResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ProductImgUploadRequest.PRODUCTIMG)) {
						JSONArray products = rsp.getJSONArray

						(ProductImgUploadRequest.PRODUCTIMG);
						JSONObject product = products.getJSONObject

						(0);
						productImgDeleteResponse.setProductImg

						(TaobaoProductJSONConvert
								.convertJsonToProductImg(product));
					}

				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return productImgDeleteResponse;
	}

	public ProductPropImgDeleteResponse productPropImgDelete(
			ProductPropImgDeleteRequest productPropImgDeleteRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ProductPropImgDeleteRequest.PICID,
				productPropImgDeleteRequest.getPicId());
		params.put(ProductPropImgDeleteRequest.PRODUCTID,
				productPropImgDeleteRequest.getProductId());
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.PRODUCT_PROPIMG_DELETE
						.getMethod(), sessionId, params));
		ProductPropImgDeleteResponse productPropImgDeleteResponse = new ProductPropImgDeleteResponse(
				response);
		// 平台访问成功
		if (productPropImgDeleteResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(productPropImgDeleteResponse.getBody());
				parseError(productPropImgDeleteResponse, json);
				// 访问淘宝成功
				if (productPropImgDeleteResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ProductPropImgUploadRequest.PRODUCTPROPIMG)) {
						JSONArray products = rsp
								.getJSONArray(ProductPropImgUploadRequest.PRODUCTPROPIMG);
						JSONObject product = products.getJSONObject(0);
						productPropImgDeleteResponse
								.setProductPropImg(TaobaoProductJSONConvert
										.convertJsonToProductPropImg(product));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return productPropImgDeleteResponse;
	}

	public VasProductGetResponse vasProductGet(VasProductGetRequest vasRequest,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareVasProductGet(vasRequest);
		return getVasProduct(params, sessionId);
	}

	protected Map<String, Object> prepareVasProductGet(
			VasProductGetRequest vasRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.SUB_PROD_ID, vasRequest.getSubProdId());
		return params;
	}

	protected VasProductGetResponse getVasProduct(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SUB_PROD_GET.getMethod(), sessionId, params));
		VasProductGetResponse vasResponse = new VasProductGetResponse(response);

		if (vasResponse.isSuccess()) {
			try {
				JSONObject jsonBody = new JSONObject(vasResponse.getBody());
				parseError(vasResponse, jsonBody);
				if (vasResponse.isSuccess()) {
					JSONObject rsp = jsonBody.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.VAS_PRODUCT)) {
						JSONObject jsonVas = rsp.getJSONObject(ApiConstants.VAS_PRODUCT);
						VasProduct vasProduct = TaobaoVasJSONConvert.convertJsonToVasProduct(jsonVas);
						vasResponse.setVasProduct(vasProduct);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}

		return vasResponse;
	}

	public TimegetResponse timeget() throws TaobaoApiException, ParseException{
		Map<String, Object> params = new HashMap<String, Object>();
		return sendmaintimeget(params);
	}

	protected TimegetResponse sendmaintimeget(Map<String, Object> params)throws TaobaoApiException, ParseException{
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TIME_MAIN.getMethod(),  params));
		TimegetResponse timegetResponse = new TimegetResponse(response);
		// 平台成功访问
		if (timegetResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(timegetResponse.getBody());
				parseError(timegetResponse, json);
				// 访问淘宝成功
				if (timegetResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.MAIN_TIME)) {
						JSONArray tbtime = rsp.getJSONArray(ApiConstants.MAIN_TIME);
						JSONObject times = tbtime.getJSONObject(0);
						try {
							timegetResponse.setMaintime(DateUtil.strToDate((times
													.getString(ApiConstants.REMAIN_TIME))));
						} catch (JSONException e) {
							throw new TaobaoApiException(e);
						}
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}

		return timegetResponse;
	}

	public GuarantyFundsGetResponse guarantyFundsGet(
			GuarantyFundsGetRequest request, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.BEGIN_DATE, request.getBeginDate());
		params.put(ApiConstants.END_DATE, request.getEndDate());
		return getGuarantyFunds(params, sessionId);
	}

	protected GuarantyFundsGetResponse getGuarantyFunds(Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.GUARANTY_FUNDS_GET.getMethod(), sessionId, params));
		GuarantyFundsGetResponse gfsResponse = new GuarantyFundsGetResponse(response);

		if (gfsResponse.isSuccess()) {
			try {
				JSONObject jsonBody = new JSONObject(gfsResponse.getBody());
				parseError(gfsResponse, jsonBody);
				if (gfsResponse.isSuccess()) {
					JSONObject rsp = jsonBody.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.GUARANTY_FUNDS)) {
						JSONArray jsonRoot = rsp.getJSONArray(ApiConstants.GUARANTY_FUNDS);
						List<GuarantyFund> guarantyFunds = TaobaoSellerJSONConvert
								.convertJsonArrayToGuarantyFundList(jsonRoot);
						gfsResponse.setGuarantyFunds(guarantyFunds);
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}

		return gfsResponse;
	}

	public ItemVideoDeleteResponse itemVideoDelete(
			ItemVideoDeleteRequest itemVideoDeleteRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareItemVideoDelete(itemVideoDeleteRequest);
		return sendItemVideoDelete(params, sessionId);
	}
	
	protected Map<String, Object> prepareItemVideoDelete(
			ItemVideoDeleteRequest itemVideoDeleteRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.ID, itemVideoDeleteRequest.getId());
		params.put(ApiConstants.IID, itemVideoDeleteRequest.getIid());
		params.put(ApiConstants.LANG, itemVideoDeleteRequest.getLang());
		return params;
	}

	protected ItemVideoDeleteResponse sendItemVideoDelete(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_VIDEO_DELETE.getMethod(),
						sessionId, params));
		ItemVideoDeleteResponse itemVideoDeleteResponse = new ItemVideoDeleteResponse(response);
		//访问平台成功
		if (itemVideoDeleteResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemVideoDeleteResponse.getBody());
				parseError(itemVideoDeleteResponse, json);
				//访问淘宝成功
				if (itemVideoDeleteResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.VIDEOS)) {
						JSONArray videos = rsp.getJSONArray(ApiConstants.VIDEOS);
						JSONObject video = videos.getJSONObject(0);
						itemVideoDeleteResponse.setIid(video.getString(ApiConstants.IID));
						try {
							itemVideoDeleteResponse.setModified(DateUtil.strToDate(video
											.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemVideoDeleteResponse;
	}

	public ItemVideoUploadResponse itemVideoUpload(
			ItemVideoUploadRequest itemVideoUploadRequest, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareItemVideoUpload(itemVideoUploadRequest);
		return sendItemVideoUpload(params, sessionId);
	}

	protected Map<String, Object> prepareItemVideoUpload(
			ItemVideoUploadRequest itemVideoUploadRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.ID, itemVideoUploadRequest.getId());
		params.put(ApiConstants.VIDEO_ID, itemVideoUploadRequest.getVideoId());
		params.put(ApiConstants.IID, itemVideoUploadRequest.getIid());
		params.put(ApiConstants.LANG, itemVideoUploadRequest.getLang());
		return params;
	}

	protected ItemVideoUploadResponse sendItemVideoUpload(
			Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(
				this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_VIDEO_UPLOAD.getMethod(),
						sessionId, params));
		ItemVideoUploadResponse itemVideoUploadResponse = new ItemVideoUploadResponse(response);
		//访问平台成功
		if (itemVideoUploadResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(itemVideoUploadResponse.getBody());
				parseError(itemVideoUploadResponse, json);
				//访问淘宝成功
				if (itemVideoUploadResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.VIDEOS)) {
						JSONArray videos = rsp.getJSONArray(ApiConstants.VIDEOS);
						JSONObject video = videos.getJSONObject(0);
						itemVideoUploadResponse.setIid(video.getString(ApiConstants.IID));
						try {
							itemVideoUploadResponse.setModified(DateUtil.strToDate(video
											.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemVideoUploadResponse;
	}
	
	public ProductStatSearchResponse productStatSearch(ProductStatSearchRequest request) throws TaobaoApiException
	{
		Map<String, Object> params = request.getParams();
		TaobaoResponse tr = this.getFetch().fetch(this.getServiceUrl(), getTemplateRequest(TaobaoApiMethod.PRODUCTSTAT_SEARCH.getMethod(), params));
		ProductStatSearchResponse response = new ProductStatSearchResponse(tr);
		try{
		    JSONObject json = new JSONObject(response.getBody());
		    response.fillResponse(json);
		}catch(JSONException e){
			throw new TaobaoApiException(e);
		}
		return response;	
	}
	
	public ProductStatGetResponse productStatGet(ProductStatGetRequest request) throws TaobaoApiException
	{
		Map<String, Object> params = request.getParams();
		TaobaoResponse tr = this.getFetch().fetch(this.getServiceUrl(), getTemplateRequest(TaobaoApiMethod.PRODUCTSTAT_GET.getMethod(), params));
		ProductStatGetResponse response = new ProductStatGetResponse(tr);
		try{
		    JSONObject json = new JSONObject(response.getBody());
		    response.fillResponse(json);
		}catch(JSONException e){
			throw new TaobaoApiException(e);
		}
		return response;	
	}
	
	public ProductPriceStatGetResponse productPriceStatGet(ProductPriceStatGetRequest request) throws TaobaoApiException
	{
		Map<String, Object> params = request.getParams();
		TaobaoResponse tr = this.getFetch().fetch(this.getServiceUrl(), getTemplateRequest(TaobaoApiMethod.PRODUCT_PRICE_STAT_GET.getMethod(), params));
		ProductPriceStatGetResponse response = new ProductPriceStatGetResponse(tr);
		try{
		    JSONObject json = new JSONObject(response.getBody());
		    response.fillResponse(json);
		}catch(JSONException e){
			throw new TaobaoApiException(e);
		}
		return response;	
	}

	public SkusCustomGetResponse skusCustomGet(SkusCustomGetRequest req, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareSkusCustomGet(req);
		return getCustomSkus(params, sessionId);
	}

	protected Map<String, Object> prepareSkusCustomGet(SkusCustomGetRequest skusCustomGetRequest) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.OUTER_ID, skusCustomGetRequest.getOuterId());
		params.put(ApiConstants.FIELDS, skusCustomGetRequest.getFields());
		return params;
	}

	protected SkusCustomGetResponse getCustomSkus(Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.SKUS_CUSTOM_GET.getMethod(), sessionId, params));
		SkusCustomGetResponse skusCustomGetResponse = new SkusCustomGetResponse(response);
		if (skusCustomGetResponse.isSuccess()) {
			JSONObject json;
			try {
				json = new JSONObject(skusCustomGetResponse.getBody());
				parseError(skusCustomGetResponse, json);
				if (skusCustomGetResponse.isSuccess()) {
					// 处理返回结果
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.SKUS)) {
						JSONArray skus = rsp.getJSONArray(ApiConstants.SKUS);
						skusCustomGetResponse.setSkus(TaobaoSkuJSONConvert
								.convertJsonArrayToSkuList(skus));
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return skusCustomGetResponse;
	}

	public ItemRecommendDeleteResponse itemRecommendDelete(ItemRecommendDeleteRequest req,
			String sessionId) throws TaobaoApiException {
		Map<String, Object> params = prepareItemRecommendDelete(req);
		return deleteRecommendItem(params, sessionId);
	}

	protected Map<String, Object> prepareItemRecommendDelete(ItemRecommendDeleteRequest req) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.IID, req.getIid());
		return params;
	}

	protected ItemRecommendDeleteResponse deleteRecommendItem(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_RECOMMEND_DELETE.getMethod(), sessionId, params));
		ItemRecommendDeleteResponse itemRecommendDeleteRequest = new ItemRecommendDeleteResponse(
				response);
		// 平台成功访问
		if (itemRecommendDeleteRequest.isSuccess()) {
			try {
				JSONObject json = new JSONObject(itemRecommendDeleteRequest.getBody());
				parseError(itemRecommendDeleteRequest, json);
				// 访问淘宝成功
				if (itemRecommendDeleteRequest.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						JSONObject item = items.getJSONObject(0);
						itemRecommendDeleteRequest.setIid(item.getString(ApiConstants.IID));
						try {
							itemRecommendDeleteRequest.setModified(DateUtil.strToDate(item
									.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemRecommendDeleteRequest;
	}

	public ItemRecommendAddResponse itemRecommendAdd(ItemRecommendAddRequest req, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareItemRecommendAdd(req);
		return addRecommendItem(params, sessionId);
	}

	protected Map<String, Object> prepareItemRecommendAdd(ItemRecommendAddRequest req) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(ApiConstants.IID, req.getIid());
		return params;
	}

	protected ItemRecommendAddResponse addRecommendItem(Map<String, Object> params,
			String sessionId) throws TaobaoApiException {
		TaobaoResponse response = this.getFetch().fetch(this.getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.ITEM_RECOMMEND_ADD.getMethod(), sessionId, params));
		ItemRecommendAddResponse itemRecommendAddResponse = new ItemRecommendAddResponse(response);
		// 平台成功访问
		if (itemRecommendAddResponse.isSuccess()) {
			try {
				JSONObject json = new JSONObject(itemRecommendAddResponse.getBody());
				parseError(itemRecommendAddResponse, json);
				// 访问淘宝成功
				if (itemRecommendAddResponse.isSuccess()) {
					// 对返回结果进行处理
					JSONObject rsp = json.getJSONObject(ApiConstants.RSP);
					if (rsp.has(ApiConstants.ITEMS)) {
						JSONArray items = rsp.getJSONArray(ApiConstants.ITEMS);
						JSONObject item = items.getJSONObject(0);
						itemRecommendAddResponse.setIid(item.getString(ApiConstants.IID));
						try {
							itemRecommendAddResponse.setModified(DateUtil.strToDate(item
									.getString(ApiConstants.MODIFIED)));
						} catch (ParseException e) {
							throw new TaobaoApiException(e);
						}
					}
				}
			} catch (JSONException e) {
				throw new TaobaoApiException(e);
			}
		}
		return itemRecommendAddResponse;
	}

	public TradeGetResponse tradeSnapshotGet(TradeGetRequest req, String sessionId)
			throws TaobaoApiException {
		Map<String, Object> params = prepareTradeGet(req);
		return getTradeSnapshot(params, sessionId);
	}

	protected TradeGetResponse getTradeSnapshot(Map<String, Object> params, String sessionId)
			throws TaobaoApiException {
		TaobaoResponse rsp = getFetch().fetch(getServiceUrl(),
				getTemplateRequest(TaobaoApiMethod.TRADE_SNAPSHOT_GET.getMethod(), sessionId, params));
		TradeGetResponse tradeGetResponse = new TradeGetResponse(rsp);

		// 访问淘宝成功
		if (tradeGetResponse.isSuccess()) {
			try {
				JSONObject jsonRoot = new JSONObject(tradeGetResponse.getBody());
				parseError(tradeGetResponse, jsonRoot); // 容错
				if (tradeGetResponse.isSuccess()) { // 容错之后是否还成功
					jsonRoot = jsonRoot.getJSONObject(ApiConstants.RSP);
					if (jsonRoot.has(ApiConstants.TRADES)) {
						JSONObject trade = jsonRoot.getJSONArray(ApiConstants.TRADES)
								.getJSONObject(0);
						tradeGetResponse.setTrade(TaobaoTradeJSONConvert.convertJsonToTrade(trade));
					}
				}
			} catch (Exception e) {
				throw new TaobaoApiException(e);
			}
		}

		return tradeGetResponse;
	}
}